I minimalized the code here. newitem is a base class(baseItem class).
healthPotion <=== consumable <===== baseItem
my consumable class has a pure virtual function that is overriden in healthPotion class ( if that matters)
item is just a CEGUI window which I use for storing data in this code.
Code: Select all
healthPotion* omg = (healthPotion*)newitem;
//I can directly cast newitem to healthpotion and I can call virtual function, so the cast is correct.
the memory location of omg = 0x0aa8c480
item->setUserData(newitem);
omg = (healthPotion*)item->getUserData();
//But when I set the userdata of the cegui::Window( which accepts a void) and then cast it back to healthPotion. I CAN'T use the virtual function and the cast is not correct.
the memory location of omg = 0x0aa8c484
Doesnt CEGUI::Window just store the pointer without changing? Or am I missing something about pointers and type-casting? or maybe virtual functions I have in consumable class
And the location of pointers change if I set and get the user data but shouldn't they stay the same?