*p=new int; invalid conversion?

int *p;
*p=new int;
Why is this an invalid conversion?
p is a pointer, and *p is the integer that p is pointing at. "new int" is also an int, right?
new int; does not return an integer. It allocates an unnamed integer somewhere in memory, and returns a pointer to it.

1
2
3
4
5
6
7
8
9
10
int* p;
p = new int;  // new int creates an unnamed integer (let's call that int 'foo')
   // it then returns a pointer to foo
   // we assign that pointer to p
   // p now points to foo

*p = 5;  // assigns 5 to foo

delete p;  // does not delete p, but instead, deletes whatever p points to
   // since p points to foo, this will delete foo 
Thanks a lot.
Topic archived. No new replies allowed.