Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ basic question - parametrized and default constructors

C++ basic question - parametrized and default constructors

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++debugging
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    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

    M S 2 Replies Last reply
    0
    • V 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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • V 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

        S Offline
        S Offline
        shiraztk
        wrote on last edited by
        #3

        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.

        V 1 Reply Last reply
        0
        • S shiraztk

          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.

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups