Hi, 

Im not sure its the right subject so... :)

Here is my problem, I got class Vehicle, class Taxi which is an extension of 
Vehicle, and class Limo which is extension of Taxi. Each class has print method 
which is an overrided cout<< method. Another method is getClassName which print 
the name of each class. Each of these methods is totally different in each 
class.

So the idea is to simulate a parking lot. I use vector to as the parking lot. 
Each time a car parked, I pushed it to the vector. Since the vector can contain 
all types of vehicle, I use  vector<Vehicle*> parkingLot;

The problem is when I loop the vector and call the cout<< method it all 
redirected to Vehicle's cout<<. The weird thing is it call the correct 
getClassName Method. Here is the code:

for(int i = 0; i<parkingLot2.size(); i++)
{
  //call the overrided cout<< method
  cout<<*parkingLot2.at(i)<<endl;

  //call a simple method
  cout << parkingLot2.at(i)->getClassName() << endl;
}

I really hope you can get the idea. I want to make sure why I cant override the 
cout<< method in 'child' class.


Thank you in advance.






      

Reply via email to