in all my other experiments i have done, my variables go out of scope as intended, but when i put variables in the main method, they don't go out of scope or that's what it seems like because the destructor never gets called:
#include <string> #include <iostream> using namespace std; #define PRINT(s) cout << s #define PRINTLN(s) PRINT(s) << endl class Animal { public: string name; int legs; Animal(string name, int legs) { this->name = name; this->legs = legs; } ~Animal(){ PRINTLN("deleting"); } static Animal createAnimal() { PRINTLN("creating"); return Animal("animal", 4); } }; int main() { PRINTLN("start"); Animal a = Animal::createAnimal();//or Animal a("hello", 5); PRINTLN("end running method"); PRINTLN("end"); system("pause"); return 0; //should print out "deleting" here //because of a going out of scope }
includes?