Hi all,
I have a class A:
class A
{
public:
virtual double getValue() = 0;
}
And a class B:
class B : public A
{
public:
virtual double getValue() { return 0.0; }
}
And then in main() I do:
A * var;
var = new B[100];
std::cout << var[0].getValue(); //This works fine
std::cout << var[1].getValue(); //This, or any other index besides 0, causes the program to quit
If instead I do:
B * var;
var = new B[100];
std::cout << var[0].getValue(); //This works fine
std::cout << var[1].getValue(); //Everything else works fine too
Everything compiles fine, but it seems as though there is something wrong with my polymorphism perhaps? I'm puzzled.