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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:13+00:00 2026-05-25T18:14:13+00:00

how to make friend function of std::make_shared() . I tried: class MyClass{ public: friend

  • 0

how to make friend function of std::make_shared().

I tried:

class MyClass{
public:
     friend std::shared_ptr<MyClass> std::make_shared<MyClass>();
     //or
     //friend std::shared_ptr<MyClass> std::make_shared();
protected:
     MyClass();
};

but it does not work (i’am using Visual Studio 2010 SP1)

  • 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-25T18:14:14+00:00Added an answer on May 25, 2026 at 6:14 pm

    How about adding a static method to your class:

    class Foo
    {
    public:
      static shared_ptr<Foo> create() { return std::shared_ptr<Foo>(new Foo); }
    private:
      // ...
    };
    

    Here’s a little hackaround:

    class Foo
    {
      struct HideMe { };
      Foo() { };
    public:
      explicit Foo(HideMe) { };
      static shared_ptr<Foo> create() { return std::make_shared<Foo>(HideMe());
    };
    

    Nobody can use the public constructor other than the class itself. It’s essentially a non-interface part of the public interface. Ask the Java people if such a thing has a name 🙂

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

Sidebar

Related Questions

To make a JavaScript class with a public method I'd do something like: function
What happens when you make a member function of a class a friend of
Can I make a function that is not member of any class be a
I have a friend who is trying to make the switch to Linux, but
make is not only useful for building your programming project, but it seems to
Is it possible to implement friend function and friend class (as in c++) in
#include <iostream> using namespace std; template <typename T> class test { T y; public:
template <> class test<int> { int y; public: test(int k) : y(k) {} friend
Trying to make a class friends with an extern C function, this code works:
I am teaching my friend how to make websites. I would like to keep

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.