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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Imitate Sealed Classes and Disable Object Copying

Java and C# have keywords that allow you to disable inheritance, but C++ does not. Find out how you can still prevent undesirable inheritance from concrete classes and how you can disable the copying of objects that aren't meant to be copied.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

he keywords final and sealed in Java and C# respectively ensure that a certain class shall not be subclassed. C++ doesn't have a similar keyword. Naive programmers are often tempted to derive from classes such as std::string and std::vector, which clearly weren't meant to be used as base classes. These illicit derivations can cause undefined behavior. Find out how to implement a compile-time constraint that blocks subclassing—plus, a technique for blocking object copying.

How can you disable inheritance from a class that isn't meant to be derived from? How do you prevent the copying of objects that aren't meant to be copied?

Restrict the access of your special member functions.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



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