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. Singleton class

Singleton class

Scheduled Pinned Locked Moved C / C++ / MFC
5 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.
  • U Offline
    U Offline
    User 1182934
    wrote on last edited by
    #1

    Hi, I have a singleton class. I need to access the static getInstance() from another file. The singleton class is defined in another file. I suppose the static variables and methods have file access. Thanks, Venkat SR

    U 1 Reply Last reply
    0
    • U User 1182934

      Hi, I have a singleton class. I need to access the static getInstance() from another file. The singleton class is defined in another file. I suppose the static variables and methods have file access. Thanks, Venkat SR

      U Offline
      U Offline
      User 1149186
      wrote on last edited by
      #2

      Add the #include diective in the .cpp where u want to create the singleton class.

      U U 2 Replies Last reply
      0
      • U User 1149186

        Add the #include diective in the .cpp where u want to create the singleton class.

        U Offline
        U Offline
        User 1149186
        wrote on last edited by
        #3

        #include "singletonFile.h" Single one ; if(one == NULL) one = Single::getInstance(); else return one;

        1 Reply Last reply
        0
        • U User 1149186

          Add the #include diective in the .cpp where u want to create the singleton class.

          U Offline
          U Offline
          User 1182934
          wrote on last edited by
          #4

          Hi, Thanks for reply, Class B is singleton. This has static getInstance(). I want to access getInstance() of Class B in Class A. Class B header is included in Class A. When i do this, it gives linker error LNK2001 unresolved external symbol getInstance(). This error occurs for other non-static functions of Class B, when called from Class A. Thanks, Venkat SR

          H 1 Reply Last reply
          0
          • U User 1182934

            Hi, Thanks for reply, Class B is singleton. This has static getInstance(). I want to access getInstance() of Class B in Class A. Class B header is included in Class A. When i do this, it gives linker error LNK2001 unresolved external symbol getInstance(). This error occurs for other non-static functions of Class B, when called from Class A. Thanks, Venkat SR

            H Offline
            H Offline
            Henry miller
            wrote on last edited by
            #5

            the format is classB::getInstance. Note that you have to prefix the class name than :: than getInstance. If you are doing that, double check your includes. Make sure you haven't accedently #IFed the class out somehow.

            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