我有一个小行星类:

class Asteroid
{
public:
    Asteroid();

    float GetMovementSpeed();
    float GetRotationSpeed();

    Placement^ GetCurrentOrientation();
    void UpdateOrientation( Placement^ placement );

    float GetPosX();
    float GetPosY();
    float GetPosZ();

    float GetRotX();
    float GetRotY();
    float GetRotZ();
private:
    float movementSpeed;
    float rotationSpeed;

    Placement^ placement;

    //float x;
    //float y;
    //float z;

    //float rotX;
    //float rotY;
    //float rotZ;
};

我已经建立了以下 vector ,并用小行星填充了它:) ...
vector<Asteroid*> asteroids;

asteroids.push_back( new Asteroid() );
asteroids.push_back( new Asteroid() );
asteroids.push_back( new Asteroid() );

for(std::vector<Asteroid*>::iterator asteroid = asteroids.begin(); asteroid != asteroids.end(); ++asteroid)
{
    asteroid-> //Can't access the methods of the asteroid class?
}

但是在迭代器内部,小行星无法访问小行星类的方法。我错过了什么?

最佳答案

迭代器的行为就像一个指针。您的类型也是指针。您要做的是首先“取消引用”迭代器,然后使用指针:

(*asteroid)->doSomething();

10-04 10:36