[英]my vector is of type <T*>, how do i now get to its value when using the iterator?
我有一個小行星班:
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<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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.