Okay there are a few errors. I'm glad you attempted it and asked for help instead of just asking someone to write it for you. Kudos to you.
When you are allocating the memory in the constructor you need to allocate room for 3 characters instead of 1.
The line should be:
To indicate we want 3 characters. You may also want to check the pointer against NULL after this to make sure you actually got the memory. Then you need to set each character to it like this.
Code:
p[0] = a;
p[1] = b;
p[2] = c;
Remember it is zero based so we don't index at 3. Basically we allocated using the [] to indicate we wanted an array of elements we need to change the delete line also to this:
The display code should look like this:
Code:
cout << p[2] << p[1] << p[0] << endl;
Also don't call the destructor yourself! It will be called automatically at the end of the scope in which it was created in.
Also you have a pointer to the Pointer Class in main but you don't allocate space for it. Either change it to a regular instance or allocate room. There is no problem doing:
Code:
Pointer p( 'a', 'b', 'c' );
p.Display( );
or...
Code:
Pointer *p = new Pointer( 'a', 'b', 'c' );
p->Display( );
delete p;
I wrote this in a hurry so if any of it is confusing let me know.
Any questions?