c++ - MinGW C++ : expected primary-expression before '/' token

标签 c++ windows g++ mingw32

这是我在这里的第一个问题,也是我第一次无法在网上四处寻找解决 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/

相关文章:

c++ - 在另一个结构中初始化一个结构数组

windows - 有人熟悉未记录的 ObReferenceObjectByName Windows 内核函数吗?

java - 通过 JDBC Driver Manager 运行 mysql 准备好的语句(慢于 10 秒)时,Tomcat 6 没有得到任何响应

gcc - 理解 g++ 编译标志

c++ - 编译问题: In function `_start' : undefined reference to `main' collect2: error: ld returned 1 exit status

c++ - 为什么 Visual Studio 2010 编译器不知道 __func__?

c++ - Boost::asio 中的 SOCK_SEQPACKET 支持

c++ - 如何使用 C++ 在 CSV 文件上执行逐行操作(一些 x)

windows - 如何将多个文件名传递给上下文菜单 Shell 命令?

c++ - 为什么别名模板给出冲突的声明?