Click to See Complete Forum and Search --> : allocating memory on the free store in VC++


April 14th, 1999, 04:04 AM
I am having some difficulties allocating memory on the free store when using the 'new' keyword. What I have is one class called BigClass for example. And BigClass has a public member variable pointer to another class. eg my code looks something like this in BigClass.h

public:
class OtherClass* m_pcOther; //The pointer to the other class



now in the BigClass.cpp I am trying to allocate memory for the pointer by using something like

m_pcOther = new OtherClass;



It compiles fine but I get a link error that does not look friendly. I have included it below:
error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall OtherClass::GetRuntimeClass(void)const " (?GetRuntimeClass@OtherClass@@UBEPAUCRuntimeClass@@XZ)

If anyone knows how to deal with this, I would appreciate it very much. Thanks in advance,
Thomas

Dave Lorde
April 14th, 1999, 04:17 AM
You don't say, but I'd guess OtherClass is derived from CObject? It looks like you are using serialisation or MFC's run-time typing but you haven't used the appropriate macros to declare and define the methods required.

Look at DECLARE_DYNAMIC / DECLARE_SERIAL / DECLARE_DYNCREATE, etc., and the corresponding IMPLEMENT_XXX macros.

Dave