problem in this little eg
-
plz somebody tell me whats the problem with this little example? i get an error Error 1 error LNK2019: unresolved external symbol "public: __thiscall B::B(void)" (??0B@@QAE@XZ) referenced in function _main #include <iostream> using namespace std; class A { public: A(); ~A(); }; class B : public A { public: B(); ~B(); }; int main() { A *p; p = new B; // ... delete p; }
-
plz somebody tell me whats the problem with this little example? i get an error Error 1 error LNK2019: unresolved external symbol "public: __thiscall B::B(void)" (??0B@@QAE@XZ) referenced in function _main #include <iostream> using namespace std; class A { public: A(); ~A(); }; class B : public A { public: B(); ~B(); }; int main() { A *p; p = new B; // ... delete p; }
If you declare the default constructors
A::A()
andB::B()
then you must provide an implementation as well (the same applies to the destructorsA::~A()
B::~B()
). Hence you either write:class A
{
};
class B : public A
{
};or
class A
{
public:
A(){}
~A(){}
};
class B : public A
{
public:
B(){}
~B(){}
};:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]