i know class comparable has no member named score but high_score_element inherits from 'comparable', and high_score_element has memeber 'score' and i want to compare with that. how do i do that?
(just partial code below)
quite confused. suppose, in addition to above code, we have the following code:
1 2
vector<comparable*> vector_to_comparable;///vector to hold comparable ///class
vector_to_comparable.push_back(new high_score_element());
now does accessing the pointer by vector_to_comparable[0] takes us to comparable class or high_score_element class?
also this way can or can't we access the data field stored in high_score_element class.
edit: @coder777 am using jumping into c++. haven't yet come across dynamic_cast. just basics of inheritance.can u suggest to solve without using dynamic_cast for now?
how about maintaining an internal score inside the implementation of your high_score_element.compare() method?
after all, I see your comparable class is an interface, so everything deriving this should implement it's own compare() method.