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; }
2 Answers
+ 2
Here is an exact match to your question where it is already explained:
https://www.sololearn.com/discuss/2028288/?ref=app
And here are very similar problems that deal with the same underlying mechanics:
https://www.sololearn.com/discuss/1501191/?ref=app
https://www.sololearn.com/discuss/1019036/?ref=app
https://www.sololearn.com/discuss/1510164/?ref=app
https://www.sololearn.com/discuss/1203725/?ref=app
0
Shadow thank you very much!