+ 2
What will be the result of C++ code?
#include <iostream> #include <memory> #include <vector> #include <algorithm> #include <functional> using namespace std; // gcc -o test-1 test.cpp /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.3.2/libstdc++.so class A { int fvalue; static int ginstance_count; public: A() : fvalue(0) { ++A::ginstance_count; cout << "A::A()" << endl; } ~A() { --A::ginstance_count; cout << "A::~A()" << endl; } static void leakReport() { cout << ginstance_count << " instances alive" << endl;
1 Antwort
+ 2
Entering the block (using for_each)
A::A()
A::A()
A::A()
List::~List result: 3 instances alive
Left the block
Entering the block (well-working code)
A::A()
A::A()
A::A()
A::~A()
A::~A()
A::~A()
List::~List result: 3 instances alive
Left the block