Click here to Skip to main content
11,433,997 members (61,945 online)
Click here to Skip to main content

Tagged as

Making Your Classes Copy-safe

, 11 Dec 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Prevent default copy constructor and assignment operator side effect

I decided in the middle of my project to make my project follow coding standard, and be more secure and encapsulated.  For me, a small macro definition changed everything just by disabling coping for all objects and preventing generation of default copy constructor and assignment operator.

#define DISABLE_COPY(CLASS_NAME) \
private: \  
CLASS_NAME ( const CLASS_NAME & );               // NOT IMPLEMENTED  \ 
CLASS_NAME & operator = ( const CLASS_NAME & );  // NOT IMPLEMENTED 

Inside your class, add this macro with the class name as parameter; just beside DECLARE_MESSAGE_MAP macro, for example.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Huzifa Terkawi
Software Developer (Senior)
Syrian Arab Republic Syrian Arab Republic
C++ , MFC , Win32 professional Developer

Comments and Discussions

 
Questionprivate: Pin
alexander_st11-Dec-12 21:17
memberalexander_st11-Dec-12 21:17 
AnswerRe: private: Pin
Mr. Tines12-Dec-12 2:03
memberMr. Tines12-Dec-12 2:03 
AnswerRe: private: Pin
Huzifa Terkawi12-Dec-12 3:46
memberHuzifa Terkawi12-Dec-12 3:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 12 Dec 2012
Article Copyright 2012 by Huzifa Terkawi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid