0

Output of C++ code

Can someone explain why this code outputs 6? It is completely mind-boggling to me... #include <iostream> #include <vector> using namespace std; class A{ public: static int cnt; A(int a){} ~A(){++cnt;} }; int A::cnt = 0; int main() { vector<A> v(4,1); v.push_back(1); cout << A::cnt << endl; return 0; }

25th May 2021, 4:49 AM
Edward Finkelstein
Edward Finkelstein - avatar
2 Answers
25th May 2021, 7:11 AM
Shadow
Shadow - avatar
0
Shadow thank you very much!
25th May 2021, 4:27 PM
Edward Finkelstein
Edward Finkelstein - avatar