Home
friends [entries|archive|friends|userinfo]
Andrew

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Wierd Code [Dec. 20th, 2009|08:25 pm]

digipen

[windowrunner]
So I want to share some code with you guys that has been giving me problems all day. Does this make sense to you?

void TargetThisObj(void * pObj){
    if(pObj){
        //Assumes pObj is a ptr to an Obj
        //that inherits from both GuyObj and IUnit
        pTargetGuy = (GuyObj *)pObj;               
        pTargetUnit = (IUnit*)pObj;
    }else{
        //note=>  class Bush : public GuyObj, public IUnit{
        Bush* pBush = GetABush();
        pTargetGuy  = pBush;
        pTargetUnit = pBush;
    }
    ASSERT((void*)pTargetGuy==(void*)pTargetUnit);
    ...
}

The weird thing to me is that the ASSERT is false. Now tell me if I'm wrong but I've been assuming that base pointers have the same value as derived pointers. So even though the pTargetGuy and pTargetUnit are pointers to two different base classes I thought they should share the same address in memory, which is the pointer to the derived class that inherits from them both.

Now I'm programming on the ARM processor with CodeWarrior and I want to know if this ASSERT is false because of the target platform or would it always be false in general for all of C++?

thoughts?
link11 comments|post comment

navigation
[ viewing | most recent entries ]

Advertisement