(Prob a duplicate)
I would really like to have function type()
returning some value that can symbolize either class but it seems like it doesn't work that way.
#include <iostream>
class A {
public:
char type() { return 'A'; }
};
class B : public A {
public:
char type() { return 'B'; }
};
class C : public A {
public:
char type() { return 'C'; }
};
auto main() -> int{
A *b = new B;
A *c = new C;
std::cout << b->type() << "\n"; // leads to 'A' but expecting 'B'
std::cout << c->type() << "\n"; // leads to 'A' but expecting 'C'
return 0;
}