Ashish Negi
Ashish Negi

Reputation: 5301

Singleton without copy constructor

I am viewing a source code and it has got a singleton class like :

class A {
    private:
     A() {}
     ~A() {}
};

And i see no copy constructor and assignment operator. When i talked about it, i got the response that it would not fail.

But i had read that making copy constructor and assignment operator private or inaccessible is important. But i am unable to generate some breaking test cases.

What test case can create two objects of this class ?

Upvotes: 0

Views: 127

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258568

Assuming you can get a hold of an instance of A, you could copy it with

A* a = new A(instance);

An automatic variable wouldn't work because of the private destructor.

Upvotes: 3

Related Questions