return type of the constructor in C++

后端 未结 3 1709
走了就别回头了
走了就别回头了 2021-01-01 20:17

I know that there is no return type of the constructors in C++

However, the code below compiles right. What is returned by the constructor in the code below?

3条回答
  •  庸人自扰
    2021-01-01 21:00

    The syntax T(), where T is some type, is a functional-cast notation that creates a value-initialized object of type T. This does not necessarily involve a constructor (it might or it might not). For example, the int() is a perfectly valid expression and type int has no constructors. In any case, even if type T has a constructor, to interpret T() as "something returned from constructor" is simply incorrect. This is not a constructor call.

提交回复
热议问题