Why does my destructor appear to be called more often than the constructor?

后端 未结 3 677
失恋的感觉
失恋的感觉 2020-12-11 16:02
#include
using namespace std;

class A{
public:
    static int cnt;
    A()
    { 
        ++cnt; 
        cout<<\"constructor:\"<

        
3条回答
  •  孤街浪徒
    2020-12-11 16:37

    You need to count copy constructor calls as well. In C++11 there are also move constructors that need to be taken into account.

提交回复
热议问题