这是我在这里的第一个问题,也是我第一次无法在网上四处寻找解决 C++ 问题的方法。我在这方面相对缺乏经验,不确定什么是相关的,所以我只会发布我认为可能有用的内容。
我正在使用 SDL 制作跨平台应用程序。我在 Windows 7(64 位)上使用 MinGW 4.6.1,并在另一台计算机上安装了 Ubuntu。
它在 Ubuntu(使用 g++)上编译良好,没有任何提示,但是当我尝试在我的 Windows 机器上使用 g++ 编译时,出现以下错误:
...matrix.cpp:77:17: error: expected primary-expression before '/' token
...matrix.cpp:78:11: error: expected primary-expression before '/' token
...matrix.cpp:79:17: error: expected primary-expression before ')' token
...matrix.cpp:79:28: error: expected primary-expression before ')' token
...matrix.cpp:80:19: error: expected primary-expression before ')' token
...matrix.cpp:80:30: error: expected primary-expression before ')' token
据我所知,这个函数没有什么特别之处(特别是因为它在我的 Ubuntu 设置上编译得很好):
Matrix *Matrix::projection(float near, float far, float top, float right) {
x1 = near/right;
y2 = near/top;
z3 = -(far+near)/(far-near);
z4 = -(2*far*near)/(far-near);
w3 = -1.0;
y1 = z1 = w1 =
x2 = z2 = w2 =
x3 = y3 =
x4 = y4 = w4 = 0.0;
return this;
}
万一重要,这里是 Matrix 类:
class Matrix { // row-major matrix
public:
float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
Matrix();
Matrix (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p);
Matrix (float *f);
Matrix *identity();
Matrix *translation(float x, float y, float z);
Matrix *rotation(float a, float i, float j, float k);
Matrix *rotation(Quaternion q);
Matrix *projection(float near, float far, float top, float right);
Matrix operator*(Matrix m);
void operator*=(Matrix m);
Matrix operator/(float f);
void operator/=(float f);
Matrix operator*(float f);
void operator*=(float f);
void operator=(float *f);
float *getArray();
};
最佳答案
我大胆的猜测是 near
和/或 far
被定义为宏,可能因此可以编译古老的 16 位 DOS/Windows 代码。
尝试在函数前添加 #undef near
和 #undef far
看看是否有帮助。
关于c++ - MinGW C++ : expected primary-expression before '/' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8731872/