I'm trying to run different codes according to what class the template T is passed as. I have 2 classes: Media and Customer. I have a template T and a function add(T type). What I want it to be able to do is effectively recognise which Class is being passed from T and add that type to an array as shown below.
template <typename T>
void add(T type){
if(type = Customer) { // This is pseudo code of what I want it to do
allCustomers.push_back(type);
cout << "Added Successfully";
}
else if (type = Media){
allMedia.push_back(type);
cout << "Added Successfully";
}
And this is how i'm trying to pass it:
l.add(new book("test","test"));
I'm sorry if I didn't explain this better, but if anyone could help, that would be great! Thanks.
Aucun commentaire:
Enregistrer un commentaire