[Cs3] explicitly deleting constructors

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Mar 14 17:02:34 EDT 2016


CS3 students,

I mentioned this in class. There is a syntactic feature of C++11
(rather than C++11) standard that allows to explicitly prohibit use of
a constructor (or overloaded assignment) without making them private:


  MyClass(Myclass &) = delete;  // prohibits constructor use.

When a constructor is private, it can still be used in other class
methods. When it is explicitly deleted, any invocation causes
compile-time errors. On the couse's webpage I gave an example of a
singleton implementation with explicit constructor delete.

Thanks,
-- 
Mikhail


More information about the cs3 mailing list