pure virtual method
Hi,
I am probably trying to do something really stupid.
There is a class shape:
class Shape
{
public:
Shape();
virtual ~Shape();
....
virtual bool inside(prec_t x, prec_t y) = 0;
....
virtual Shape * copy() = 0;
....
};
and a class circle which is derived from shape
class Circle : public Shape
{
public:
Circle(prec_t radius);
Circle(prec_t radius, prec_t outerRadius);
Circle();
virtual ~Circle();
....
bool inside(prec_t x, prec_t y);
....
Shape * copy();
....
};
ok, now the class Surface has a member of type Shape *:
class Surface
{
public:
....
Shape* myShape;
....
}
finally the last class derives from Surface:
class EvenASph : public Surface
{
public:
....
Surface outerShell;
Surface lowerShell;
....
}
now in this class I am trying to do something like
1) upperShell.shape = this->shape->copy();
2) lowerShell.shape = this->shape->copy();
this seems to work, the compiler does not complain.
But I occasionally encountered crashes when I call
upperShell.shape->inside()
Occasionally meaning, either it does not work at all -
the program immediately causes a Segmentation fault -
or it just work fine and never crashes.
I used the compiler g++ 4.0.3.
If instead of 1 and 2) I do, for example
lowerShell.shape = this->shape
I always get an error when trying to execute:
pure virtual method called
terminate called without an active exception
Am I trying to do something really illegal?
Thanks,
Maximilian