Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7172707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:40:14+00:00 2026-05-28T15:40:14+00:00

I have used singleton calss following the example: singleton class But i get the

  • 0

I have used singleton calss following the example:

singleton class

But i get the error as “Unresolved external symbols”

this is the code i tried out:

#include<iostream>
using namespace std;

class singleton
{
    int value;
    static singleton *instance;
protected:
    singleton()
    {
        value=0;
    }
public:
    static void initialize()
    {
        if(instance==NULL)
            singleton();
        else
            cout<<"An instance of singleton already exist...";
    }
    static singleton& getInstance()
    { 
        return *instance; 
    }
    int getValue() 
    { 
        return value; 
    }

};

void main()
{
    singleton::initialize();
}

A little bit explanation on Singleton classes would be really great. The scenario its used. advantages and drawbacks. Alternatives to Singleton. etc

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:40:15+00:00Added an answer on May 28, 2026 at 3:40 pm

    For a start, I think:

    singleton();
    

    should be:

    instance = new singleton();
    

    The way you have it, you’re not actually storing the newly instantiated object so instance will always be null.

    It’s also good form to explicitly set statics with:

    singleton *singleton::instance = 0;
    

    (outside the class definition).

    In fact, it’s possibly better to start with the baseline singleton code and work your way up from there. This is a standard-form pointer version:

    #include <iostream>
    
    class singleton {
        protected:
            static singleton *instance;
            singleton() { }
        public:
            static singleton *getInstance() {
                if (instance == 0)
                    instance = new singleton();
                return instance;
            }
    };
    singleton *singleton::instance = 0;
    
    int main() {
        singleton *s1 = singleton::getInstance();
        singleton *s2 = singleton::getInstance();
        std::cout << s1 << '\n';
        std::cout << s2 << '\n';
        return 0;
    }
    

    You can see that both pointers are the same from the output:

    0xbc0358
    0xbc0358
    

    Or the reference version, since that seems to be what you’re aiming for:

    #include <iostream>
    
    class singleton {
        protected:
            static singleton *instance;
            singleton() { }
        public:
            static singleton& getInstance() {
                if (instance == 0)
                    instance = new singleton();
                return *instance;
            }
    };
    singleton *singleton::instance = 0;
    
    int main() {
        singleton &s1 = singleton::getInstance();
        singleton &s2 = singleton::getInstance();
        std::cout << &s1 << '\n';
        std::cout << &s2 << '\n';
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code public class Something { [Inject] public Configuration config {get;set;}
I have always used a Singleton class for a registry object in PHP. As
I have a singleton class used to initialise error_handling. The class as is takes
I have a compiled external library that I'm using in my (Objective-C++) code. This
I was confused when I first started to see anti-singleton commentary. I have used
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have used this in my HTML: <q> Hai How r u </q> Which
My app has a singleton class called CycleManager. I have created a sealed class
Actually i have created an singleton class. Now my singleton class extends Activity, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.