Показать сообщение отдельно
Старый 27.06.2009, 23:34   #3
Genius
Знающий
 
Аватар для Genius
 
Регистрация: 02.11.2007
Сообщений: 255
Написано 27 полезных сообщений
(для 43 пользователей)
Ответ: Хитрая хитрость

Сообщение от jimon Посмотреть сообщение
эх

class position
{
public:
int x,y,z;
};

class human:public position
{
public:
int height, width;
};


class car:public position
{
public:
int speed;
};

void setposition(position * obj)
{
obj->x = 1;
}

...
human * lol1 = new human;
setposition(lol1);
delete lol1;
car * lol2 = new car;
setposition(lol2);
delete lol2;
...
если ты хочешь назначать переменную по номеру то это можно, но является жудким говнокодом
Я бы вообще сделал так:

class Car;
class Human;

class GameObject
{
public:
     float x,y,z,pitch,yaw,roll;
     bool alive;

     bool isAlive() { return alive; }

     Car* getCar(){return 0;}
     Human* getHuman(){return 0;}

    virtual void setPosition(float _x,float _y,float _z){ x=_x;y=_y;z=_z; }
    virtual void setOrientation(float _pitch,float _yaw,float _roll){ pitch=_pitch;yaw=_yaw;roll=_roll;}

    virtual void update(){}
};

class Car : public GameObject
{
public:

     Car* getCar(){return this;}
  
     void setPosition(float x,float y,float z) 
     {
          GameObject::setPosition(x,y,z);
          ....
     }

     void setOrientation(float pitch,float yaw,float roll)
     {
         GameObject::setOrientation(pitch,yaw,roll);
         ...
     }

     void update()
     {
        car physic update...
     }
};

class Human : public GameObject
{
public:

     Human* getHuman(){return this;}
  
     void setPosition(float x,float y,float z) 
     {
          GameObject::setPosition(x,y,z);
          ....
     }

     void setOrientation(float pitch,float yaw,float roll)
     {
         GameObject::setOrientation(pitch,yaw,roll);
         ...
     }

     void update()
     {
         if(health <= 0)alive=false;
     }
};

class CarDriver : public Human
{
....
};

GameObject* car = new Car();
GameObject* human = new Humman();

if(car->getCar() != 0)car->setPosition(40,10,0);
if(human->getHuman() != 0)human->setPosition(40,15,0);
А вообще я не совсем понял вопрос.
(Offline)
 
Ответить с цитированием