passing arguement

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 Class A{......};

class B{
public:
  void function(A * p_obj)
  {
   //Do Something
  }
};

int main()
{
  B obj;
  obj.function(new A()); // need clarification here
  return 0;
}


in the above code
1) is the memory created in heap and class pointer pushed to stack of function.
1) will it lead to memory leak
2) who will delete new a() efficiently in above code, caller or callee function?
caller is unable to delete the allocated object because it has no its address,
So it is function that must delete the object.
Last edited on
Topic archived. No new replies allowed.