I was studying for my exam, and I came across the following question:
How many instances of MyClass exist in memory when program execution reaches point X?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
MyClass *func1(MyClass a) {
MyClass b;
MyClass * c = new MyClass();
return c;
}
void func2(MyClass d) {
MyClass e;
MyClass * f = new MyClass();
MyClass * g = func1(e);
POINT X
return;
}
int main() {
MyClass h;
MyClass * i = new MyClass();
func2(h);
return 0;
}
I think the answer is 5, for objects e,f,g,h, and i. However, I am not sure if an onject is instantiated if it is specified as a function parameter? For example, would the objects a,c,d be object instantiations?