Ok i got a little problem, i made 2 classes named World and Player (being for some 3D engine) well anyways both classes have some functions which recieve an handle of the other object so they can get data (so some world function needs to get some vars from a player and some player functions need some vars from the world)

when i include my files as following:

include world.inc
include player.inc

the functions in player.inc can use things like .World.UnitSize or something, but functions in world.inc cant access any values like .Player.X when i put player.inc above world.inc i get errors in player.inc

when i put both classes into 1 file it works fine but i want to have 2 seperate include files is there a way to get around this?
Posted on 2005-03-29 14:40:04 by Scorpie
Hi Scopie!
This problem is a classical include problem where 2 objects need the definition of the other to get access to the data structure. As they are very close classes, the best and obvious way is to put both together in the same file. If you don?t want to do this, you have to prototype the shared methods. This way, the compiler knows that the method definitions come later.
If you are using OA32, you can use the option to compile one of the objects into a library. This will solve the problem, since OA32 takes the work of prototyping the methods. Nevertheless, I don?t recommend to do it in the R&D phase to facilitate the debugging of your app.

Hope this helps...  ;)

Regards,

Biterider
Posted on 2005-03-29 15:28:13 by Biterider
ah i see, this prototyping does it allow me to make 3 files? 1 file containing both classes and one file containg all the world functions and one file containg all the player functions? (im on another PC now so i cant try it out).

The main reason why i dont want to put it all together in one file is, now it are just 2 small classes but later on there probably will be a lot of classes which all need to be able to access one another's data structures.

Thanks for the reply, Scorpie

ps. putting one class into a library doesnt seem very practical indeed especially at this stage of development where both classes will be changed a lot i think it even will be faster writing in two files which i put together for compiling instead of compiling one into a library :p
Posted on 2005-03-29 17:57:37 by Scorpie
EnterHostedClass and LeaveHostedClass will do what you need, but they're not very easy to understand.
They just toggle one internal variable. When we're in a "HostedClass" (the name's tricky, had run out of ideas), ATC:
1)  defines the structure of the class:
myClass struct
vTable dd ?
var1 dd ? ; long var1
var2 dd ?
myClass ends

2) ...actually does almost everything as in normal mode (out of a "HostedClass") , with the exception of: building vtables and the real constructor+destructor. So it doesn't take even a byte for that new class, which is marked as hosted

We use HostedClasses when: writing ddraw.inc and d3d.inc - to define the COM object DirectDraw/Direct3D.

Or you can just try to put the class definitions in a separate file (.inc), but that shouldn't be done in one case - when you put the class' actual code (methods) in a separate .lib file :) . For now go for the .inc file  ;)
Posted on 2005-03-29 21:36:25 by Ultrano
Hi Scorpie
A trick you can use is to define a separate base class that defines the variables and shared methods as abstract methods of the inherited object class. Let us name this base class ?A? and the inherited class ?B?. The third class ?C?.

Now you can include the object definition of ?A?, then ?C? and finally ?B?
Since ?A? holds all the information that needs class ?C?, all works smoothly.
Class ?A? is only a wrapper class, so you have to redefine the abstract methods.

The trick here is to pass the correct instance pointer and the use of an OOP property called polymorphism.

The drawback of this approach is that you need a few more bytes more in memory to define class ?A?, but you will have NO performance loss!  8)

Regards,

Biterider
Posted on 2005-03-30 02:46:11 by Biterider