I have a Base class and a Derived class, only the parts of the class in question are listed for brevity:
Code:
class Base
{
public:
static const int type;
Base (int x=0, int y=0);
~Base();
};
class Derived : public Base
{
public:
static const int type;
Derived (int x=0, int y=0);
~Derived();
};
const int Base::type = 0;
const int Derived::type = 1;
Base::Base (int x, int y)
{
cerr << "You created an object of type " << type;
}
Base::~Base()
{
cerr << "Destructor called for object of type " << type;
}
Derived::Derived (int x, int y) : Base (x, y)
{}
Derived::~Derived()
{}
Now in my code I declare an array of pointers which will be used to point to objects of either the Base or Derived Classes:
Code:
Base *ClassPointers[2];
ClassPointers[0] = new Base();
ClassPointers[1] = new Derived();
Now if I look in my error log, I see these messages:
You created an object of type 0
You created an object of type 0
Of course, I expect the messages to look like this:
You created an object of type 0
You created on object of type 1
What gives? Help would be greatly appreciated.