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

前端 未结 10 1521
情深已故
情深已故 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 16:55

    Who says you can't? You just have to know how.

    void Foo::Bar() {
      *this = Foo(); // Reset *this
    }
    

提交回复
热议问题