Hey y'all, hope I write this question correctly. My question is directed at the line quiz[i]->display();
From what I understand, the -> operator de references the pointer and then calls the member function of that object. My question is why cant I write something like *(quiz[i]).display() ? To me it seems like those two statements are equivalent, where they both say "de reference the pointer and call the member function on what the pointer contains" however the second one doesn't work and I get an error saying "expression must have a class type". Thanks in advance, just trying to make sure I really understand what is going on here.
string response;
cout << boolalpha;
Question* quiz[3];
quiz[0] = new Question;
quiz[0]->set_text("Who was the inventor of C++?");
quiz[0]->set_answer("Bjarne Stroustrup");
ChoiceQuestion* cq_ptr = new ChoiceQuestion;
cq_ptr->set_text("In which country was the inventor of C++ born?");
cq_ptr->add_choice("Australlia", false);
cq_ptr->add_choice("Denmark", true);
cq_ptr->add_choice("Korea", false);
cq_ptr->add_choice("United States", false);
quiz[1] = cq_ptr;
NumericQuestion* nq_ptr = new NumericQuestion;
nq_ptr->set_text("How many liters are in a gallon?");
nq_ptr->set_answer(3.78541);
quiz[2] = nq_ptr;
for(int i = 0; i < 3; i++)
{
quiz[i]->display();
cout << "Your answer: ";
getline(cin, response);
cout << quiz[i]->check_answer(response) << endl;
}
}