About Store Forum Documentation Contact



Post Reply 
storing as derived class in Game.ObjMemx
Author Message
Rollcage Offline
Member

Post: #1
storing as derived class in Game.ObjMemx
Hi, I don't think it's currently possible but here is what I'd like to do.

Esentially to have a Game.ObjMemx<baseclass> for storing Gameobjects but then be able to store pointers to derived classes inside.

so...

class base

class derived1 : base

class derived2 : base

Then have

World.ObjCreate() be able to store a pointer to derived class in the Memx.
This way we can call virtual functions for the derived classes for a better object oriented approach.
(This post was last modified: 08-27-2012 01:32 PM by Rollcage.)
08-27-2012 01:31 PM
Find all posts by this user Quote this message in a reply
Rollcage Offline
Member

Post: #2
RE: storing as derived class in Game.ObjMemx
Surely this would be helpful to others.. I don't think it's currently possible in th engine
08-30-2012 02:18 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: storing as derived class in Game.ObjMemx
Hello,

Game::ObjMemx cannot store pointers, it must store objects.
One Game::ObjMemx can store only 1 type of class.
Please use

class base
class derived1 : base
class derived2 : base

Game::ObjMemx<Derived1> Derived1s;
Game::ObjMemx<Derived2> Derived2s;

for performing multiple operations on both containers, you can use auto-casting:
example 1:
Game::ObjMemx<Base> &a=Derived1s;
Game::ObjMemx<Base> &b=Derived2s;

example 2:
void func(Game::ObjMemx<Base> &objs)
{
}
func(Derived1s);
func(Derived2s);
09-01-2012 02:15 PM
Find all posts by this user Quote this message in a reply
Rollcage Offline
Member

Post: #4
RE: storing as derived class in Game.ObjMemx
Thanks! It sounds like for what I want I should create a new obj_type for each class of unit but ill have to think about it
09-01-2012 03:04 PM
Find all posts by this user Quote this message in a reply
Post Reply