For solving some exercise I need to have global objects run in a C++ code like below. But when I run it using MS VS compiler, that global variable will not be run.
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Tracer {
string cons, dest;
public:
Tracer(string c, string d) : cons(c), dest(d) {
cout << "A(n) '" << cons << "' object was created.\n";
}
void mem_ob() {
Tracer<string> s("string", "string");
}
~Tracer() {
cout << "The '" << dest << "' object was destructed.\n";
}
};
//----------------------------
Tracer<double> d("double", "double");
//------------------------------------
int main() {
Tracer<int> t("int", "int");
t.mem_ob();
system("pause");
return 0;
}
The d
object isn't run. How to get it run please?