I've followed the instructions I got from my last post and re-wrote my code.
My header file
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <typeinfo>
#include "Tour.h"
#include "GuidedTour.h"
using namespace std;
class TourManager {
private:
vector<Tour *> tours;
void setupTour();
string getUserInput();
string displayMainMenu();
void displayTourDetails();
void callDisplayOnEach();
void addBookingsToTour();
public:
TourManager();
void go();
};
Then I have a function to populate the "list" vector with tour and guidedTour objects.
void TourManager::setupTour() {
tours.push_back(new Tour("FP001", "Fun Park 3 Day Pass", 110.00));
tours.push_back(new GuidedTour("SK003", "Learn to Ski Adventure Tour", 240.00, "28/07
}
void TourManager::callDisplayOnEach() {
for (vector<Tour *>::iterator it = tours.begin() ; it != tours.end(); ++it)
{
if(typeid(*it) == typeid(GuidedTour))
{
cout << "Guided Tour" << "\n";
}
else
{
cout << "NOT Guided Tour : " << typeid(*it).name() << "\n";
}
}
}
However I always seems to be getting back Tour objects. EG: it always prints NOT Guided Tour.
how do I archive polymorphic behavior?
Can you please advice? (I'm new to C++) My required to use C++98
Many thanks