I'm trying to understand what is meant by suppression of copy/move ctor/assignment. For instance in a cases where a class declares a destructor but does not declare move/copy ctor/assignment operations.
I originally was under the impression that these would simply not be generated (deleted) and compilation would fail. But after some experimentation this doesn't seem to be the case. However, if I explicitly mark the copy constructor as deleted then compilation does fail.
Note the snippet below was taken from 'The C++ Programming Language (4th edition)' Section 17.6.3.3. In the discussion that follows Stroustrup remarks:
"Also, Handle declares a destructor: this suppresses the generation of copy and move operations."
template< typename T >
class Handle {
T *p;
public:
Handle( T *pp) : p{pp}{}
T &operator*() {
return *p;
}
// NOTE: I've added this method for testing.
// this will cause compilation to fail, but commenting this
// out does not fail compilation and g++ with -Wall emits no
// warning
Handle( const Handle &other ) = delete;
~Handle() {
delete p;
}
};
int
main( void ) {
int x = 3;
Handle< int >a( &x );
Handle< int >b( a );
return 0;
}
Compiled with g++ 6.3.0 with -std=c++11
So what exactly is meant by 'suppression' does it mean we don't get the corresponding methods generated unless some part of the code makes use of it? In other words, does having Handle< int >b( a ); override the 'suppression'?