Dynamic memory used in function

Suppose I have the following code (I saw this kind on the Internet):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class foo{
	public:
	int m , n;
	foo(int x , int y){
		m=x;
		n=y;
	}
};

void f(foo *a){
//...
}

int main(){
f(new foo(2,3));
return 0;
}


Would the variable after "new" be deleted after the function operates? (So it saves space)
Would the variable after "new" be deleted after the function operates?

No. Use an automatic object.
So you mean I have to have another dummy variable?
I have another question. If f(foo *a) has a dynamic variable with "new". Is the variable deleted after the function operates?
All objects created with new has to be deleted with delete.
He. Thank you. That helps me a lot!
closed account (1yR4jE8b)
You could have checked this yourself by making a destructor that prints something to the screen and see if it's get's called at any point in that program ;) .
Topic archived. No new replies allowed.