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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What wrong with my code ?

What wrong with my code ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
5 Posts 4 Posters 1 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi ALL I wrote some code and i dont know why the compiler throw me this error message : RegistryCall.obj : error LNK2001: unresolved external symbol "private: static class CRegistryCall * CRegistryCall::m_cRegistryCallObject" (?m_cRegistryCallObject@CRegistryCall@@0PAV1@A) RegistryCall.obj : error LNK2001: unresolved external symbol "private: static bool CRegistryCall::m_bExistObject" (?m_bExistObject@CRegistryCall@@0_NA) The code : H file : class CRegistryCall { private: CRegistryCall(); public: static CRegistryCall* CreateInstance(); virtual ~CRegistryCall(); private: static bool m_bExistObject; static CRegistryCall* m_cRegistryCallObject; }; Cpp File : CRegistryCall::CRegistryCall() { m_bExistObject = true; m_cRegistryCallObject = NULL; } CRegistryCall::~CRegistryCall() { if(m_bExistObject) { m_bExistObject = false; delete m_cRegistryCallObject; } } CRegistryCall* CRegistryCall::CreateInstance() { if(!m_bExistObject) { m_bExistObject = true; m_cRegistryCallObject = new CRegistryCall(); } return m_cRegistryCallObject; } This class need to act as singleTon. Thanks for any help.

    _ R H 3 Replies Last reply
    0
    • L Lost User

      Hi ALL I wrote some code and i dont know why the compiler throw me this error message : RegistryCall.obj : error LNK2001: unresolved external symbol "private: static class CRegistryCall * CRegistryCall::m_cRegistryCallObject" (?m_cRegistryCallObject@CRegistryCall@@0PAV1@A) RegistryCall.obj : error LNK2001: unresolved external symbol "private: static bool CRegistryCall::m_bExistObject" (?m_bExistObject@CRegistryCall@@0_NA) The code : H file : class CRegistryCall { private: CRegistryCall(); public: static CRegistryCall* CreateInstance(); virtual ~CRegistryCall(); private: static bool m_bExistObject; static CRegistryCall* m_cRegistryCallObject; }; Cpp File : CRegistryCall::CRegistryCall() { m_bExistObject = true; m_cRegistryCallObject = NULL; } CRegistryCall::~CRegistryCall() { if(m_bExistObject) { m_bExistObject = false; delete m_cRegistryCallObject; } } CRegistryCall* CRegistryCall::CreateInstance() { if(!m_bExistObject) { m_bExistObject = true; m_cRegistryCallObject = new CRegistryCall(); } return m_cRegistryCallObject; } This class need to act as singleTon. Thanks for any help.

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      Yanshof wrote:

      RegistryCall.obj : error LNK2001: unresolved external symbol "private: static bool CRegistryCall::m_bExistObject" (?m_bExistObject@CRegistryCall@@0_NA)

      When you use a static variable in a class you need to initialize it with some value in the .cpp file.(or outside the class) SO for the variables that you are using as static (eg for m_bExistObject) put this line on top of the .cpp file. bool CRegistryCall::m_bExistObject =true; and you can do like wise for the other variables too...

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      1 Reply Last reply
      0
      • L Lost User

        Hi ALL I wrote some code and i dont know why the compiler throw me this error message : RegistryCall.obj : error LNK2001: unresolved external symbol "private: static class CRegistryCall * CRegistryCall::m_cRegistryCallObject" (?m_cRegistryCallObject@CRegistryCall@@0PAV1@A) RegistryCall.obj : error LNK2001: unresolved external symbol "private: static bool CRegistryCall::m_bExistObject" (?m_bExistObject@CRegistryCall@@0_NA) The code : H file : class CRegistryCall { private: CRegistryCall(); public: static CRegistryCall* CreateInstance(); virtual ~CRegistryCall(); private: static bool m_bExistObject; static CRegistryCall* m_cRegistryCallObject; }; Cpp File : CRegistryCall::CRegistryCall() { m_bExistObject = true; m_cRegistryCallObject = NULL; } CRegistryCall::~CRegistryCall() { if(m_bExistObject) { m_bExistObject = false; delete m_cRegistryCallObject; } } CRegistryCall* CRegistryCall::CreateInstance() { if(!m_bExistObject) { m_bExistObject = true; m_cRegistryCallObject = new CRegistryCall(); } return m_cRegistryCallObject; } This class need to act as singleTon. Thanks for any help.

        R Offline
        R Offline
        raghuji rao
        wrote on last edited by
        #3

        if u writing in a console application then in the project-- settings options, set use mfc in a shared dll option. it will work out

        _ 1 Reply Last reply
        0
        • R raghuji rao

          if u writing in a console application then in the project-- settings options, set use mfc in a shared dll option. it will work out

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          raghuji.rao wrote:

          if u writing in a console application then in the project-- settings options, set use mfc in a shared dll option. it will work out

          :doh:

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          1 Reply Last reply
          0
          • L Lost User

            Hi ALL I wrote some code and i dont know why the compiler throw me this error message : RegistryCall.obj : error LNK2001: unresolved external symbol "private: static class CRegistryCall * CRegistryCall::m_cRegistryCallObject" (?m_cRegistryCallObject@CRegistryCall@@0PAV1@A) RegistryCall.obj : error LNK2001: unresolved external symbol "private: static bool CRegistryCall::m_bExistObject" (?m_bExistObject@CRegistryCall@@0_NA) The code : H file : class CRegistryCall { private: CRegistryCall(); public: static CRegistryCall* CreateInstance(); virtual ~CRegistryCall(); private: static bool m_bExistObject; static CRegistryCall* m_cRegistryCallObject; }; Cpp File : CRegistryCall::CRegistryCall() { m_bExistObject = true; m_cRegistryCallObject = NULL; } CRegistryCall::~CRegistryCall() { if(m_bExistObject) { m_bExistObject = false; delete m_cRegistryCallObject; } } CRegistryCall* CRegistryCall::CreateInstance() { if(!m_bExistObject) { m_bExistObject = true; m_cRegistryCallObject = new CRegistryCall(); } return m_cRegistryCallObject; } This class need to act as singleTon. Thanks for any help.

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Yes you need to two lines to your code in cpp file bool CRegistryCall::m_bExistObject =true; And also for cRegistryCallObject:)


            WhiteSky


            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