RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Blocking Undesirable Object Copying and Implicit Conversions

C++ doesn't offer a direct mechanism for blocking undesirable copying or preventing implicit conversion of arguments. However, with some code tweaks you can work around these problems.


ingletons, stream objects, and other classes must disable copying and assignment. However, C++ doesn't yet provide a direct mechanism for disabling copying. Another related problem exists with undesirable conversions of arguments passed to a function. The following sections will show how to work around these limitations to block undesirable copying and assignments and prevent implicit conversions of arguments.

There's no means to suppress the compiler's automatic declaration of a copy constructor and an assignment operator—even if you wish to disable copying and assignment of certain objects. Likewise, you cannot instruct the compiler to disable automatic conversions of arguments passed to a function.

Declare the copy constructor and assignment operator explicitly as private members without defining them. To prevent undesirable implicit conversions of arguments, declare dummy signatures that intercept the wrong types of arguments.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date