I have another odd problem with Objective C inheritance. I have a protocol called IGameObject, a class GameObject that inherits from NSObject and IGameObject and finally a Player that inherits from GameObject..
The problem is that when I assign a Player* to a IGameObject*, this produces an error, but it works ok when I assign a Player* to a GameObject*. I haven’t seen that this is not possible in all I have read. Here the code:
-(IGameObject*) clone
{
Player* p=(Player*) 0xFFfFFFFF;
//Throws an error saying that Cannont initialise a variable of type IGameObject with an value of Player*
IGameObject* go=p;
//This works perfectly
GameObject* go2=p;
return [[Player alloc] initWithGameObject:self];
}
Could anybody guess what is happening?
Thanks in advance.
When returning (or declaring) a type that is only known by its interface, don’t treat it as an object pointer. Instead, use:
And:
This should clear up that warning.
Sidenote: Why in the world are you assigning
pto a memory address?!