2011-06-15 9 views
0

actorManager型のオブジェクトの配列を格納するactorVectorというベクトルがあります。C++オブジェクトのベクトルへのポインタ、属性にアクセスする必要があります

actorManagerクラスにはプライベート属性があり、GLFrame型のオブジェクトでもあります。 GLFrameオブジェクトへのポインタを返すアクセサ、getFrame()を持っています。

actorVectorのポインタを関数に渡しました。したがって、actorManager型のオブジェクトのベクトルへのポインタです。

私は、この関数のパラメータとしてGLFrameオブジェクトを渡す必要があります:私は現在のようなそれをやろうとしてきたが、イムは、任意の結果を得ていない

modelViewMatrix.MultMatrix(**GLFrame isntance**); 

modelViewMatrix.MultMatrix(*(*actorVector)[i].getFrame()); 

優先順位のルールは、上記と同等であることを意味していること

modelViewMatrix.MultMatrix(*((*actorVector)[i].getFrame())); 

注:MultMatrixを想定し

+0

あなたはコンパイラエラーを取得しているお試しください! –

+2

関連する宣言を表示することは良いアイデアです。そのような記述は、実際には説明的ではないためです。 –

答えて

3

ActorManagerまたは参照(ポインタではなく)によって、あなたはこれが欲しい取ります:

modelViewMatrix.MultMatrix(*(*actorVector)[i].getFrame()); 

しかし、それはあなたがすでに持っているものですので、あなたが私たちを言っていない何かがなければならない...

+0

彼は 'actorVectorはポインタではなくベクトルであると言ったので、' * actorVector'は何かを意味しますか?私たちはもっと情報が必要だと私は同意します。 – Nemo

+0

@ニモ:OPは "私はactorVectorのポインタを関数に渡しました"と言います... –

+0

ええ、私はそれを逃しました。 – Nemo

0

modelViewMatrix.MultMatrix(*(*p)[i].getFrame());

#include <vector> 
using std::vector; 

class GLFrame {}; 
class actorManager { 
    /* The actorManager class has a private attribute, which is also an 
    object of type GLFrame. It has an accessor, getFrame(), which returns 
    a pointer to the GLFrame object. */ 
private: 
    GLFrame g; 
public: 
    GLFrame* getFrame() { return &g; } 
}; 

/* I need to pass the GLFrame object as a parameter to this function: 
    modelViewMatrix.MultMatrix(**GLFrame isntance**); */ 
class ModelViewMatrix { 
public: 
    void MultMatrix(GLFrame g){} 
}; 
ModelViewMatrix modelViewMatrix; 

/* I have a vector called actorVector which stores an array of objects of 
type actorManager. */ 
vector<actorManager> actorVector; 

/* I have passed a pointer of actorVector to a function, so its a pointer 
to a vector of objects of type actorManager. */ 
void f(vector<actorManager>* p, int i) { 
/* I need to pass the GLFrame object as a parameter to this function: 
    modelViewMatrix.MultMatrix(**GLFrame isntance**); */ 
    modelViewMatrix.MultMatrix(*(*p)[i].getFrame()); 
} 

int main() { 
    f(&actorVector, 1); 
} 
関連する問題