C++指向对象向量的指针,需要访问属性

发布于 2024-11-15 08:37:19 字数 453 浏览 3 评论 0原文

我有一个名为 actorVector 的向量,它存储 actorManager 类型的对象数组。

actorManager类有一个私有属性,它也是一个GLFrame类型的对象。它有一个访问器 getFrame(),它返回一个指向 GLFrame 对象的指针。

我已将 actorVector 的指针传递给函数,因此它是指向 actorManager 类型的对象向量的指针。

我需要将 GLFrame 对象作为参数传递给该函数:

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

我目前一直在尝试这样做,但没有得到任何结果。

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

有什么想法吗?

I have a vector called actorVector which stores an array of objects of type 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.

I have passed a pointer of actorVector to a function, so its a pointer to a vector of objects of type actorManager.

I need to pass the GLFrame object as a parameter to this function:

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

I've currently been trying to do it as such, but im not getting any results.

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

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把人绕傻吧 2024-11-22 08:37:19

假设 MultMatrix 通过 或通过 引用(而不是通过指针)获取 ActorManager,那么你想要这个:

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

请注意,优先级规则意味着上面的内容相当于:

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

但是,这就是您已经拥有的,所以一定有一些您没有告诉我们的事情......

Assuming MultMatrix takes an ActorManager by value or by reference (as opposed to by pointer), then you want this:

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

Note that the precedence rules mean that the above is equivalent to:

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

However, that's what you already have, so there must be something you're not telling us...

以酷 2024-11-22 08:37:19

尝试 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);
}

Try 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文