-
November 17th, 2017, 09:57 AM
#1
Promoting a derived struct to another deriving struct
Code:
struct A
{
};
struct B : public A
{
};
A* a = new A();
B* b = (B*) a;
When will this downcast fail? I just got a bad pointer out of this cast...(0xbaadf00dbaadf00d )
Thanks
Jack
Last edited by luckiejacky; November 17th, 2017 at 10:00 AM.
-
November 17th, 2017, 11:31 AM
#2
Re: Promoting a derived struct to another deriving struct
Code:
struct A
{
int a;
};
struct B : public A
{
double b;
};
A* a = new A();
The created *a has no place for double b; that is appeared to belong in struct B.
Victor Nijegorodov
-
November 17th, 2017, 07:28 PM
#3
Re: Promoting a derived struct to another deriving struct
Why this thing is always a problem? I mean I create FRAME's inside this function (the B) and return to the caller, then the caller accepts it as a derived class (the A)
Code:
newFrame->pFrameSibling
= (FRAME*)CopyFrameHierarchy((const FRAME*)other->pFrameSibling);
Even on an explict cast
Last edited by luckiejacky; November 17th, 2017 at 07:34 PM.
-
November 18th, 2017, 02:48 AM
#4
Re: Promoting a derived struct to another deriving struct
Originally Posted by luckiejacky
Why this thing is always a problem? I mean I create FRAME's inside this function (the B) and return to the caller, then the caller accepts it as a derived class (the A)
But in your OP the B is a derived class while A is the base one!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|