How do I make a class uncloneable?

G

Gaijinco

I know that by default every class has overloaded operator= and the
copy constructor.

How then can I make a class uncloneable?

Thanks.
 
G

gnuyuva

I know that by default every class has overloaded operator= and the
copy constructor.

How then can I make a class uncloneable?

Thanks.

struct unclonable
{
private:
unclonable& unclonable(const unclonable&);
unclonable& operator=(const unclonable&);
};

derive your concrete classes from this struct.
 
W

wo3kie

Much faster and readable with intention is

struct unclonable : boost::noncopyable
{

};
 
J

James Kanze

Much faster and readable with intention is
struct unclonable : boost::noncopyable
{
};

If you're familiar with Boost. I originally used something like
this long before Boost existed. I dropped it because most
maintenence programmers weren't as familiar with it as they were
with the standard idiom of making the copy constructor and the
assignment operator private. (I've since started using it
again, because I'm hoping that Boost will make it widely known.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top