Original Post
Hey everyone, I've been working on pointers recently and learning stuff about them and I've hit a snag with the 'delete' statement. Below is the code I'm testing.
int main()
{
using namespace std;
unsigned short int myVar = 5, yourVar = 20, hello;
unsigned short int * pVar = new unsigned short int;
pVar = &myVar //pVar is now pointing to myVar
*pVar = yourVar; //myVar equals yourVar
cout << "myVar:\t" << myVar << endl;
cout << "yourVar:\t" << yourVar << endl;
delete pVar;
cin >> hello;
return 0;
}
Obviously just a basic console program that changes the value of the first variable by changing the pointer value. The problem occurs after the second 'cout' so obviously it's in my delete or cin. (The cin is only used to pause the program at the end). I've tried other delete's in my compiler (Visual Studio .NET) and they've worked fine. It says it is giving me an 'assertion' error. Can anyone see what's wrong?