Let's look at this code. Why can the numbers of destructors called more than constructors?
#include <iostream>
using namespace std;
class B{
public:
B(){
cout << "constructor of B\n";
}
~B(){
cout << "destructor of B\n";
}
};
void func(B obj){
}
int main(){
B obj;
func(obj);
}
and the output is
constructor of B
destructor of B
destructor of B
I don't understand why the number of destructors called are not the same as the number of constructors called?