| | |
Hiding an Assignment Operator
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> declare it as private and just leave an empty implementation?
ideally, declare it as private and do not define it.
> Is this common/useful?
useful, yes. common, not all that much.
if there is a class that you write (for example a window), and want its instances not to have value semantics, you need to suppress any compiler-generated copy constructor and assignment operators.
see: http://www.boost.org/doc/libs/1_37_0...ss_noncopyable
ideally, declare it as private and do not define it.
> Is this common/useful?
useful, yes. common, not all that much.
if there is a class that you write (for example a window), and want its instances not to have value semantics, you need to suppress any compiler-generated copy constructor and assignment operators.
c++ Syntax (Toggle Plain Text)
struct window { // ... private: window( const window& ) ; // do not define this void operator= ( const window& ) ; // do not define this // ... }
see: http://www.boost.org/doc/libs/1_37_0...ss_noncopyable
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
•
•
•
•
> declare it as private and just leave an empty implementation?
ideally, declare it as private and do not define it.
> Is this common/useful?
useful, yes. common, not all that much.
if there is a class that you write (for example a window), and want its instances not to have value semantics, you need to suppress any compiler-generated copy constructor and assignment operators.
c++ Syntax (Toggle Plain Text)
struct window { // ... private: window( const window& ) ; // do not define this void operator= ( const window& ) ; // do not define this // ... }
see: http://www.boost.org/doc/libs/1_37_0...ss_noncopyable
![]() |
Other Threads in the C++ Forum
- Previous Thread: Factorial problem
- Next Thread: Somebody Help me please!!! I'm new to c++ and I need help
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






