M
Martin Koller
Hi list,
I have a small example which gives me "pure virtual function called".
I'm calling a virtual function in the destructor of the base class, where
the pointer used is effectively pointing to a derived class, but the whole
thing is in the process of being destroyed.
Interesting for me is also, that I get the same error if I call b->isA() in
the constructor of Base.
I just wanted to know, if this behavior is correct in C++ terms or is it a
compiler issue ? (using gcc-2.3.2 on Linux)
(Please CC me on mail)
#include <iostream>
class Base
{
public:
Base(Base *x) { b = x; };
virtual ~Base()
{
b->isA();
};
virtual int isA() = 0;
private:
Base *b;
};
class Derived : public Base
{
public:
Derived() : Base(this) { std::cerr << isA() << std::endl; };
virtual int isA() { return 1; }
};
main()
{
Derived *d = new Derived();
delete d;
}
Thanks,
Martin
I have a small example which gives me "pure virtual function called".
I'm calling a virtual function in the destructor of the base class, where
the pointer used is effectively pointing to a derived class, but the whole
thing is in the process of being destroyed.
Interesting for me is also, that I get the same error if I call b->isA() in
the constructor of Base.
I just wanted to know, if this behavior is correct in C++ terms or is it a
compiler issue ? (using gcc-2.3.2 on Linux)
(Please CC me on mail)
#include <iostream>
class Base
{
public:
Base(Base *x) { b = x; };
virtual ~Base()
{
b->isA();
};
virtual int isA() = 0;
private:
Base *b;
};
class Derived : public Base
{
public:
Derived() : Base(this) { std::cerr << isA() << std::endl; };
virtual int isA() { return 1; }
};
main()
{
Derived *d = new Derived();
delete d;
}
Thanks,
Martin