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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:37:30+00:00 2026-06-15T00:37:30+00:00

So I try this code: #ifndef TRANSMITTER_H #define TRANSMITTER_H class connector { public: static

  • 0

So I try this code:

#ifndef TRANSMITTER_H
#define TRANSMITTER_H
class connector
{   
public:
    static boost::shared_ptr<connector> Instance(){
        if(!instance)
        {
            instance = boost::shared_ptr<connector>(new connector());
        }
        return instance;
    }
private:
    connector(){}
    static boost::shared_ptr<connector> instance;
};
#endif //TRANSMITTER_H

But get link error:

Error   3   error LNK2001: unresolved external symbol "private: static class boost::shared_ptr<class connector> connector::instance" (?instance@connector@@0V?$shared_ptr@Vconnector@@@boost@@A)

What is wrong with shared_ptr I want to return? Shall I make it function scope static variable?

  • 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-15T00:37:31+00:00Added an answer on June 15, 2026 at 12:37 am

    This

    static boost::shared_ptr<connector> instance;
    

    inside your class definition is just a declaration. What you don’t seem to have is a definition of it. This definition has be outside of the class definition.

    However, you should probably prefer to do this:

    class connector
    {   
    public:
        connector(connector const&) = delete;
        connector& operator=(connector const&) = delete;
    
        static boost::shared_ptr<connector> Instance()
        {
            static boost::shared_ptr<connector> instance (new connector);
            return instance;
        }
    private:
        connector(){}
    };
    

    In this case instance is defined as a static function-local object inside your inline function definition of Instance. The nice thing about it is that this kind of initialization is guaranteed to be thread-safe in C++11.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
I just created this new class : //------------------------------------------------------------------------------ #ifndef MULTITHREADEDVECTOR_H #define MULTITHREADEDVECTOR_H //------------------------------------------------------------------------------ #include
I have this code: try { var _o, _l, i, _d = new Array(),
I have a C++ file like this #ifndef _MOVE_H #define _MOVE_H class Move {
The following code using boost::asio will not compile: #ifndef _SERVER_H_ #define _SERVER_H_ #include Connection.h
Consider the following code: #include <stdlib.h> #ifndef TRY #define TRY struct #endif TRY testme
I've got this header (redone from a boost asio example): #ifndef MSGSRV_H_ #define MSGSRV_H_
When I try this code: dict_a = dict_b = dict_c = {} dict_c['hello'] =
When I try this code: if Verbose: print("Building internam Index for %d tile(s) ..."

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.