我想用OpenGL实现一个函数来渲染C++中的圆柱体。我的功能的签名如下:参考二维阵列
#define POINTS_NUM 15
#define DEMESION 3
void drawCylinder(int slices, int segments, GLfloat (&vertices)[ POINTS_NUM ][ DEMESION ]);
我想使用对二维数组的引用来限制用户输入,但一些奇怪的行为正在发生。当我实现如上声明的函数时,链接器错误:
Error 1 error LNK2005: "float (* vase)[3]" ([email protected]@3PAY02MA) already defined in shapes.obj vase.obj VaseAndAnimation
这里vase
被定义为:
GLfloat vase[ POINTS_NUM ][ DEMESION ];
起初,我还以为有什么不对的最后一个维度。所以我在第二次审判中忽略了它。我的功能的这次声明是这样的:
void drawCylinder(int slices, int segments, GLfloat (&vertices)[ POINTS_NUM ][]);
现在编译时错误时为(vase
定义不改变)被调用时:
drawCylinder(10, 10, vase);
编译错误:
Error 1 error C2087: 'vertices' : missing subscript d:\visual studio 2008\projects\project1\computer graphics\vaseandanimation\shapes.h 25 VaseAndAnimation
Error 2 error C2664: 'drawCylinder' : cannot convert parameter 3 from 'GLfloat [14][3]' to 'GLfloat (&)[14][1]' d:\Visual Studio 2008\Projects\Project1\Computer Graphics\VaseAndAnimation\vase.cpp 64 VaseAndAnimation
Error 3 error C2087: 'vertices' : missing subscript d:\visual studio 2008\projects\project1\computer graphics\vaseandanimation\shapes.h 25 VaseAndAnimation
Error 4 error C2087: 'vertices' : missing subscript d:\Visual Studio 2008\Projects\Project1\Computer Graphics\VaseAndAnimation\shapes.cpp 12 VaseAndAnimation
从这个错误,我可以看到参数vertices
真的被视为一个二维数组的参考,但为什么vase
解析为float (* vase)[3]
在我的第一个版本?
我的IDE是Visual Studio 2008.我还没有尝试过使用GCC;那是行为编译器依赖的?
希望有人能帮我摆脱陷阱。
可能的重复[如何将对二维数组的引用传递给函数?](http://stackoverflow.com/questions/404232/how-do-i-pass-a-参考到二维阵列到函数) – 2010-06-24 04:37:01