Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.


advertisement
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.

 

 

Sitemap