What if I write return statement in constructor?

前端 未结 2 1179
一个人的身影
一个人的身影 2020-12-07 19:21

What if I write return statement in constructor? Is it standard conformant?

struct A
{ 
     A() { return; } 
};

The above code compiles fi

2条回答
  •  隐瞒了意图╮
    2020-12-07 19:50

    Perhaps the notion of having typeless return in constructors is to control the termination of constructor function.

    struct A
    { 
    // more definitions     
    A() 
    { 
    if( !goodToGoOn)  
     return;
    // the rest of the stuffs go here
    } 
    };
    

提交回复
热议问题