What does a constructor return?

后端 未结 6 511
礼貌的吻别
礼貌的吻别 2020-12-14 23:37

My question is what does a constructor return? This question is not quite different from \"What is the return type of a constructor?\" I have read somewhere that a construct

6条回答
  •  被撕碎了的回忆
    2020-12-15 00:24

    what about this:

    int main() {
    const empty &er = empty();
    empty *ep = const_cast(er); //casting away conentness to make changes in the members
    cout<<"\n main ends \n";
    //dtor get called here
    }
    

    ctor returns a const reference to a memory location(*this), you can cast away the const and use its as a nonconst normal object like empty *e = new e;

提交回复
热议问题