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 1085227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:39:47+00:00 2026-05-16T22:39:47+00:00

I asked a question earlier today about singletons, and I’m having some difficulties understanding

  • 0

I asked a question earlier today about singletons, and I’m having some difficulties understanding some errors I encountered. I have the following code:

Timing.h

class Timing {

public:
    static Timing *GetInstance();
private:
    Timing();
    static Timing *_singleInstance;
};

Timing.cpp

 #include "Timing.h"

 static Timing *Timing::GetInstance() {  //the first error
    if (!_singleInstance) {
        _singleInstance = new Timing();  //the second error
    }
    return _singleInstance;
}

There are two errors in this code which I can’t figure out.

  1. The method GetInstance() is declared in the header as static. Why in the cpp file do I have to omit the word static? It gives the error: “cannot declare member function ‘static Timing* Timing::GetInstance()’ to have static linkage”. The correct way to write it is:

    Timing *Timing::GetInstance() { ... }  
    
  2. Why can’t I write _singleInstance = new Timing();? It gives the error: “undefined reference to Timing::_singleInstance”. I solved this error by defining _singleInstance as a global var in the cpp file.

  • 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-16T22:39:48+00:00Added an answer on May 16, 2026 at 10:39 pm

    1: static means “local linkage” when used for a function declaration/definition outside a class-declaration.

    Local linkage means that the particular function can only be referenced from code inside this particular file, and that doesn’t make much sense with a method in a class.

    2: Since your class declaration can be included multiple times, the actual storage for the static member should be defined in the cpp-file:

    #include "Timing.h"
    
    Timing* Timing::_singleInstance;
    
    Timing *Timing::GetInstance() {  //the first error
        if (!_singleInstance) {
            _singleInstance = new Timing();  //the second error
        }
        return _singleInstance;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Earlier today I asked a question about environ , and one of the more
Earlier today I asked a question about configuring log4net from code and got an
Earlier today I asked this question . After spending some time investigating this issue,
I know I have asked this question in a different manner earlier today but
Earlier today a question was asked regarding input validation strategies in web apps .
I asked a question earlier about which language to use for an AI prototype.
I asked a question earlier which elicited some great responses. Here's the earlier question
Ok, I asked a question earlier about Flex and ADO.NET Data Services but didn't
Earlier I asked a question about why I see so many examples use the
This is a follow up to a question I asked earlier today regarding the

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.