   n00b C++ question:)
  Hi!I''ll try to explain the problem.... Say i have a Ship class, and a Weapon class, and Ship has a Weapon, likeclass BaseShip  : public BaseObject{public:cWeapon Weapon1;cWeapon Weapon2;...}I need to get some Ship''s variables in a function in the Weapon class (Ship->Position and Ship->Direction for example), what is the right way to do that? The way i do it, i have "BaseShip *Ship" in the Weapon class, and when the Weapon is created, the constructor is called with a pointer to the ship as parameter, and that pointer goes to this "BaseShip *Ship". Maybe there is a better way to do that, or simplier? Some "this" pointer for the parent object maybe?Hope i made it clear, sorry for my englishThanks in advance. 
quote:Original post by needto  IThe way i do it, i have "BaseShip *Ship" in the Weapon class, and when the Weapon is created, the constructor is called with a pointer to the ship as parameter, and that pointer goes to this "BaseShip *Ship".  The approach you''re using is perfectly valid. Also, I think passing the pointer of the parent to the children has to be done manually, since c++ can''t just go guessing for the parent class instance.-Nik ;  Thank you very much for the answerThere''s one more question, that bugs me right now:I have a global structure: stl vectors of ships and projectiles, declared in main.cpp. So to add a projectile from Weapon class, i use "extern cGO GameObjects;" in Weapon.cpp. Is that the right way?;  I wouldn't use globals in that case, but make a "World" class in which all of the game objects reside as children. Also, a member of the world class would be the projectile vector - when you pass the world pointer to any child nodes, the children then have access to the projectile vector via the world (or maybe even a projectile manager class, if we go fancy ).Of course, you can use extern global if you want to, but that makes it more difficult to, for example, load a world from a file.-Nik [edited by - Nik02 on February 5, 2004 10:22:20 AM];  That seems very reasonable, thanksIts been a while since i began to write programs, but i can''t organize code in a good way yet... So much to learn;  It pays to design your game properly before you begin coding it  I didn''t realize that in my first programming years, but when I got my first large programming job, I had to learn - otherwise I couldn''t have kept track of the project. The product was very successful, and completed well before due time, because of this new-found discipline of "design" -Nik 