I have written a sample test code as,
Class A
{
main ()
{
A *a;
B *ptr;
B* A::func() const {
B* ptr = new B;
return B;
}
}
and
Class B
{
// some code accessing the func() in class A
}
what i understand,
- everytime the func() is accessed from class B, a new memory location is allocated for the object
-but it is not deleted explicitly
- once the pointer is returned from a method in class A, the memory is
- If I continue to call func() say, for 1000 times(or any number), is it possible that it results into a segmentation fault if we try to access the ptr variable which is no longer existing, as there cud be other processes running (creating objects and operating system can allocate those memory to other objects which was initially reserved)
I am not sure if was able to make my query clear and understandable.
please help.
Thanks in advance