Default constructor c++

前端 未结 4 2007
南笙
南笙 2021-01-07 04:19

I am trying to understand how default constructor (provided by the compiler if you do not write one) versus your own default constructor works.

So for example I wrot

4条回答
  •  长发绾君心
    2021-01-07 05:10

     A n();
    

    declares a function, named n, that takes no arguments and returns an A.

    Since it is a declaration, no code is invoked/executed (especially no constructor).

    After that declaration, you might write something like

    A myA = n();
    

    This would compile. But it would not link! Because there is no definition of the function n.

提交回复
热议问题