Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
conditions for automatic generation of default ctor, copy ctor,and default assignment operator (oper
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="James Kanze, post: 3524547"] No. Any user defined constructor, including a copy constructor, inhibits automatic generation of the default constructor. A copy constructor is generated any time there is no user declared copy construtor. A copy assignment operator is generated any time there is no user declared copy assignment operator. A copy constructor for a class X is a non-template constructor having an X&, X const&, X volatile& or X const volatile& as its first parameter, and having default arguments for all other parameters, if any. A copy assignment operator is a non-template assignment operator having an X, X&, X const&, X volatile& or X const volatile& as parameter. Note that: -- a member function template template is never considered a copy constructor or copy assignment operator (and thus will never prevent the compiler from generating one); -- you can declare more than one copy constructor or copy assignment operator; and -- operator overload resolution is *always* used when deciding what constructor to call, even when "copying", and operator overload resolution can choose a constructor which is not a copy constructor to copy. Consider: class C { public: template< typename T > C( T& other ) ; } ; The compiler will generate a C::C( C const& ) copy constructor, which will participate in operator overload resolution: C c1 ; C c2( c1 ) ; // calls the template constructor. C c3( C() ) ; // calls the compiler generated copy // constructor. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
conditions for automatic generation of default ctor, copy ctor,and default assignment operator (oper
Top