deleting primitive and class types pointers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
#include<string>
class A
{
	public:
	A()
	{
		std::cout << "constructed." << std::endl;
	}
	~A()
	{
		std::cout << "destructed." << std::endl;
	}
};
int main()
{
	A *ao = new A();
	A* ab;
	ab = ao;
	delete ab;   // also deletes the object constructed on heap memory.
	int*  int1 = new int(20);
	int* int2;
	int2 = int1;
	delete int2;   //this does not delete the int1 created on heap.
}

what is difference between deleting these two primitive type pointer and class type pointer.
Last edited on
What makes you think the int value isn't being deleted? What are you expecting to see?
Topic archived. No new replies allowed.