2011-06-15 3 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); 
} 
관련 문제