我试图将Bouncing Bubbles处理示例移植到C++中(使用OpenFrameworks),并且我遇到了一些问题。在该类的定义中:在其类中声明一个对象
class Ball {
float x, y;
float diameter;
float vx = 0;
float vy = 0;
int id;
Ball[] others;
...
void collide() {
for (int i = id + 1; i < numBalls; i++) {
float dx = others[i].x - x;
float dy = others[i].y - y;
float distance = sqrt(dx*dx + dy*dy);
...
它看起来像对象“others”正在其自己的类中声明。我已经尝试将Ball others(<arguments>);
添加到我的C++类中,但是XCode愤怒地在我身上闪烁,并留下一个控制台消息,威胁要吃掉我未来的孩子,所以我必须做出错误的事情。我在想这可能是一个Java/Processing的东西 - 但我对C++类很新颖。
有没有办法在C++中完成同样的事情,或者我只是更好地将碰撞函数从类中移出并进入testApp类进行一些修改?
谢谢!因为我需要一个对象数组,所以我最终使用了Ball **。现在代码工作正常,尽管物理不太好,但现在已经足够了! – superkittens