Why can I not call my class's constructor from an instance of that class in C++?

前端 未结 10 1522
情深已故
情深已故 2021-01-03 16:39

When can an object of a class call the destructor of that class, as if it\'s a regular function? Why can\'t it call the constructor of the same class, as one of its regular

10条回答
  •  孤城傲影
    2021-01-03 17:13

    The constructor is there "c()" used with new, i.e.

    c objC = new c();
    

    If you want to call your constructor outside of the actual construction of the class instance then you either haven't understood the purpose of the constructor or are trying to put functionality in there that shouldn't be there.

提交回复
热议问题