C++ basic question - parametrized and default constructors
-
I have a class derived from CMultiDocTemplate and using constructor with parameters: CMyTemplate::CMyTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass) : CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass) { ..... } Now the VC++ 6.0 compiler complains that it needs a default constructor. I have added one and now the linker complains: Linking... CMyTemplate.obj : error LNK2001: unresolved external symbol "public: __thiscall CMultiDocTemplate::CMultiDocTemplate(void)" (??0CMultiDocTemplate@@QAE@XZ) Debug/0_IRA_GL_MFC.exe : fatal error LNK1120: 1 unresolved externals The linker cannot find the base class default constructor? What am I missing? Thanks for you help. Vaclav
-
I have a class derived from CMultiDocTemplate and using constructor with parameters: CMyTemplate::CMyTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass) : CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass) { ..... } Now the VC++ 6.0 compiler complains that it needs a default constructor. I have added one and now the linker complains: Linking... CMyTemplate.obj : error LNK2001: unresolved external symbol "public: __thiscall CMultiDocTemplate::CMultiDocTemplate(void)" (??0CMultiDocTemplate@@QAE@XZ) Debug/0_IRA_GL_MFC.exe : fatal error LNK1120: 1 unresolved externals The linker cannot find the base class default constructor? What am I missing? Thanks for you help. Vaclav
It seems the problem is in your creation of an object of type CMyTemplate, not in the class definition itself. The DocTemplate classes don't have default constructors - they are meant to be created with parameters. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
I have a class derived from CMultiDocTemplate and using constructor with parameters: CMyTemplate::CMyTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass) : CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass) { ..... } Now the VC++ 6.0 compiler complains that it needs a default constructor. I have added one and now the linker complains: Linking... CMyTemplate.obj : error LNK2001: unresolved external symbol "public: __thiscall CMultiDocTemplate::CMultiDocTemplate(void)" (??0CMultiDocTemplate@@QAE@XZ) Debug/0_IRA_GL_MFC.exe : fatal error LNK1120: 1 unresolved externals The linker cannot find the base class default constructor? What am I missing? Thanks for you help. Vaclav
Hi How did you create your object ? This could help you, class Base { public: Base(int k) { value = k; } private : int value; }; class Derived:public Base { public: Derived(int k):Base(k) { } private: char s; }; int main(int argc, char* argv[]) { Derived object(10); // and not Derived object; This will give those return 0; //errors as you mentioned. } Regards
The Best Religion is Science. Once you understand it, you will know God.
-
Hi How did you create your object ? This could help you, class Base { public: Base(int k) { value = k; } private : int value; }; class Derived:public Base { public: Derived(int k):Base(k) { } private: char s; }; int main(int argc, char* argv[]) { Derived object(10); // and not Derived object; This will give those return 0; //errors as you mentioned. } Regards
The Best Religion is Science. Once you understand it, you will know God.
Thanks for your replies. I am not sure what I did wrong but after deleting the default constructor it compiles and links without errors. I think my object instantiation was wrong. Unfortunately I did not have VSS running at this time so I cannot backtrack my code. Sorry. Thanks again. Vaclav