What does a constructor return?

后端 未结 6 508
礼貌的吻别
礼貌的吻别 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:32

    A constructor doesn't return anything. A constructor is called to initialize an object. A constructor can only be used to initialize an object; you can't actually call a constructor explicitly (for one thing, constructors do not have names).

    In the example you give, empty() is not a function call expression, it is value initialization. It creates a value-initialized temporary object of type empty.

提交回复
热议问题