c++ - Can a derived class be made uncopyable by declaring copy constructor/operator private in base class? -


i thought in theory answer question yes.

however, in practice, compiler (vs2010) not seem complain in following situation: have abstract base class providing common interface (yet having no data members) , various sub , subsubclasses derived it.

class base  { public:     base() {}     virtual ~base() {}      virtual void interfacefunction1() = 0;     virtual void interfacefunction2() = 0; private:     base(const base&);            // derived classes should uncopyable     base& operator=(const base&);      // no data members }; 

my compiler found unproblematic implement full copy constructors in sub- or subsubclasses.

how can make sure every class derived base uncopyable?

edit: if understand well, scott meyers explained in item 6 of effective c++ (3rd edition, 2005) idea of class uncopyable (only extended here full interface class). difference makes idea work ? (i know inherits privately, should not pose problem)

this should prevent compiler generating copy constructor derived classes not declare 1 explicitly. however, nothing prevents derived class explicitly declaring copy constructor else call copy constructor of base.

there no way make sure derived classes instantiable not copyable.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -