Copy constructors and Assignment Operators

后端 未结 3 1342
甜味超标
甜味超标 2020-12-06 14:37

I wrote the following program to test when the copy constructor is called and when the assignment operator is called:


#include 

class Test
{
public:
    T         


        
3条回答
  •  独厮守ぢ
    2020-12-06 15:29

    C++ standard 8.5/12

    The initialization that occurs in argument passing, function return, throwing an exception (15.1), handling an exception (15.3), and brace-enclosed initializer lists (8.5.1) is called copy-initialization and is equivalent to the form

    T x = a;
    

    The initialization that occurs in new expressions (5.3.4), static_cast expressions (5.2.9), functional notation type conversions (5.2.3), and base and member initializers (12.6.2) is called direct-initialization and is equivalent to the form

    T x(a);
    

提交回复
热议问题