In c++ I want to have an array of the abstract type Query which has the function calcScore()
which is a pure virtual function.
And I have two classes which are non-abstract: ConQuery and DisQuery that implements the calcScore function.
In order to do I defined the array like this:
vector<Query*> m;
and I iterate and call the function like this:
for (vector<Query*>::const_iterator it1 = index.begin() ;it1 != index.end() ; it1++)
{
cout << (*it1)->CalcScore() << endl;
}
I get an error for calling a pure virtual function of Query.
How do I make it call to the function of ConQuery or the one of DisQuery by the polymorphic type?
thanks.
Are you sure CalcScore is implemented in ConQuery and DisQuery ?
I tried this:
and it works fine under my VS2012.
Also I used it tons of times in some of my projects.
Maybe you try to push_back a Query item ( and not a con/dis ) ?