class class2
{
public:
class2();
int do_interesting_things();
.
.
.
private:
int var1;
}
class2::do_interesting_things()
{
class1* test_case = new class1();
test_case::setVar1(1);
test_case::setVar2('x');
.
.
.
return;
}
When class2::do_interesting_things() is called, a new instance of class1 is created, and the variables var1 and var2 are assigned some values. Upon return from this function, are the variables in class1 (that is, in test_case) forgotten?
Since test_case is a local variable it's destroyed when the function is done.
The memory for class1 is still there just not longer accessible -> memory leak.
Also, what's the difference between
The first is a [static] function call of a specific class
The second one calls the last overridden function (you need a variable not a class for this)
This applies basically to virtual function
By the way:
1 2
test_case::setVar1(1); // Invalid: you can call a function statically of a class not a variable
test_case::setVar2('x'); // see above