judith
judith

Reputation:

What value does the t* point to

I am looking into the pointers and I came up with code like that

class b 
{

}
class d

{

}

d* a = 0;

b *t = new b();

*t = * ( b* )a;

What does this declaration mean?
What value does t have?

Upvotes: 0

Views: 100

Answers (1)

Pubby
Pubby

Reputation: 53067

t will still be pointing to the object created with new b();. *t = changes the value of what t points to, not t itself.

Your last line contains undefined behavior as you're derefenrencing a null pointer. Also, your cast is actually a reinterpret_cast in disguise, which is something you shouldn't do.

Upvotes: 6

Related Questions