Reputation: 27
I am trying to understand the usage of smart pointers. In the below example, I intend Class B to be the smart pointer to class A. I get the following linker error
error LNK2019: unresolved external symbol "public: __thiscall ClassB::ClassB(classA *)"
I seem to be missing something with the constructor. I am not clear as to what should be passed from class A in the constructor. I would appreciate if somebody could explain.
class A
{
friend class B;
virtual methods ();
protected:
virtual ~A();
}
class B:public QSharedPointer<A>
{
B();
B(A * pData);
B(const B &data);
virtual ~ B();
}
Upvotes: 0
Views: 605
Reputation: 3361
If you are just trying to use a smart pointer then should not be trying to inherit from QSharedPointer you want something like
QSharedPointer<A> ptr(new A());
ptr->do_something();
If you are trying to implement your own smart pointer then you still most likely to not want to inherit from some other smart pointer class. You can take a look at the boost implementation of scoped_pointer for a fairly easy to understand implementation of a basic smart pointer.
Upvotes: 0
Reputation: 372794
The error you're getting is a linker error, not a compiler error, which happens (among other cases) when you prototype a function but don't implement it. Did you provide an implementation for your B::B(A*)
constructor? If so, did you compile and link it in to the resulting executable? If thenot, that would explain the answer to either question is "no," then you should easily be able to fix this by providing and linking in an implementation.
Upvotes: 2