Я создал новый узел. Как обратиться к node->question->question
, node->question->options[]
, node->question->correctans
и node->question->difficulty_level
struct node {
node *prev;
node *next;
int count;
Question question[];
};
struct Question{
String question;
String[] options;
String correctans;
int difficulty_level;
}
Я не уверен, что вы просите, но я думаю, что это то, что вы ищете:
#include <string.h>
#include <iostream>
using namespace std;
struct Question{
string *question;
string *options [4];
string correctans;
int difficulty_level;
};
struct node {
node *prev;
node *next;
int count;
Question *question[4];
}n;
int main(){
Question *q;
Question qu;
q->question = new string("This is a question"); // assign some values
q->options[0]= new string("The first option");
q->difficulty_level = 4;
qu.question = new string("another question");
qu.options[0]= new string("The second option");
qu.difficulty_level = 5;
n.question[0] = q;
n.question[1] = &qu;
//print the assigned values
cout << "Question 1 question: " << *n.question[0]->question << endl;
cout << "Question 1 Option 1: "<<*n.question[0]->options[0] << endl;
cout << "Question 1 dificulty: "<<n.question[0]->difficulty_level << endl;
cout << "Question 2 question: " << *n.question[1]->question << endl;
cout << "Question 2 Option 1: "<<*n.question[1]->options[0] << endl;
cout << "Question 2 dificulty: "<<n.question[1]->difficulty_level << endl;
}
q->question
в моем случае не будет правильным. Не так ли?
'->' является разыменованием указателя. Поскольку у вас есть массив объектов в вашем узле (а не только указатель на них), правильным способом доступа к ним будет "node.question [x]". То же самое относится к вашей структуре вопросов, то есть node.question [0].question даст строку вопроса первого вопроса, сохраненного в этом массиве узлов (если это было действительно c code...).
Надеюсь, это поможет, дайте мне знать, если вам что-то неясно.
Question question[]
? Какой вопрос вы хотели бы «отослать»?