Calling copy constructor on yourself

后端 未结 1 1224
我寻月下人不归
我寻月下人不归 2021-01-20 18:42

I am curious about what is happening in this code I wrote almost by mistake:

#include 

class Test
{
public:
  Test() {
    std::cout <<         


        
1条回答
  •  野的像风
    2021-01-20 19:21

    Since you have a member variable of type int, whose indeterminate value is copied to itself, the code is technically Undefined Behavior.

    However, in practice, with current computers nothing bad will happen. But on the third hand, nothing good happens either.

    Regarding warnings, that's a Quality Of Implementation issue. The C++ standard has nothing to say about that.

    0 讨论(0)
提交回复
热议问题