unique_ptr and singleton

std::unique_ptr<A> a(new A());

If class A inherit from Singleton class
and then I access with a->getSingleton().member();
it can be a problem?

I mean, unique_ptr and singleton can conflict or is regular?
codder wrote:
inherit from Singleton class
This statement does not make sense...
If I have a singleton class and then i do

class A : public Singleton<A>
{
//...
};

The purpose of a singleton is that there is only one instance. An instance of a derived class is also an instance of the singleton. Why is the derived class not the singleton class?
It's the singleton class but I thought it can have problems with unique_ptr
Your problem is with "inherit from singleton", not with unique_ptr
> If class A inherit from Singleton class .. it can be a problem?

Normally no. Which singleton class are you inheriting from?
@ LB: A templated singleton parent class can be used to make child singleton classes. He's probably doing this:

1
2
3
4
5
6
7
8
9
10
11
12
template <typename T>
class Singleton
{
private:
  // ctors/dtors here to enforce it can't be externally created

public:
  T& getInstance()
  {
    // get instance of child class here
  }
};



That said... I don't really understand OP's question about unique_ptr.
Topic archived. No new replies allowed.