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

  • Home
  • SEARCH
  • 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 7877669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:26:20+00:00 2026-06-03T03:26:20+00:00

class A { private: A () {} public: static A* getInstance () { return

  • 0
class A
{
    private:
        A () {}

    public:
        static A* getInstance ()
        {
            return new A ();
        }
};

int main ()
{
    A.getInstance ();
    return 0;
}

results in the error stated in the title. I do realize that if I create a variable in class A and instanciate it there and return it directly, the error will vanish.

But, here I want to understand what is the meaning of this error and why can’t I use it this way.

  • 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-06-03T03:26:21+00:00Added an answer on June 3, 2026 at 3:26 am

    You need to call the method using the scope resolution operator – :::

     A::getInstance ();
    

    Also, if this is meant to be a singleton, it’s a very bad one. Whenever you call getInstance(), you’ll receive a new object, and you’ll run into memory leaks if you forget to delete any instances.

    A singleton is usually implemented like so:

    class A
    {
        private:
            A () {}
            static A* instance;
        public:
            static A* getInstance ()
            {
                if ( !instance )
                    instance = new A ();
                return instance;
            }
    };
    
    //implementation file
    A* A::instance = NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class StaticTest { private static StaticTest stObj=new StaticTest(); private static int VAR1=10; private
public class Checker { static private int value1 = 0, value2 = 1; static
public class Bird { private static int id = 0; private String kind; public
public class SelfCallingTest { private static int counter; public void SelfCallingMethod(int counter) { Console.WriteLine(The
So I have the following: public class Singleton { private Singleton(){} public static readonly
public class Readparam { private static String method_name; public static HashMap<String, Vector<String>> getParameters(String file_name)
I have this class: public static class CsvWriter { private static StreamWriter _writer =
Let's say I have a class called AppConfig: public static class AppConfig { private
class ConfigReader { private static $instance = NULL; protected $configData = array(); public function
i have the code as below : class Singleton { private: int i; static

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.