MinGW C++:'/' 之前预期的主要表达式代币

发布于 2024-12-25 00:58:21 字数 2011 浏览 1 评论 0原文

这是我的第一个问题,也是我第一次无法通过环顾四周来在线找到 C++ 问题的解决方案。我在这方面相对缺乏经验,并且不确定什么是相关的,所以我只会发布我认为可能有用的内容。

我正在使用 SDL 制作跨平台应用程序。我在 Windows 7(64 位)上使用 MinGW 4.6.1,并在另一台计算机上使用 Ubuntu 设置。

它在 Ubuntu 上编译得很好(使用 g++),没有任何抱怨,但是当我尝试使用 g++ 在 Windows 机器上编译时,出现以下错误:

...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();
};

This is my first question here, and the first time I haven't been able to find a solution to a C++ problem online by just looking around. I'm relatively inexperienced in this area, and am not sure what's relevant, so I'll just post whatever I think might be useful.

I'm using SDL to make a cross-platform application. I'm using MinGW 4.6.1 on Windows 7 (64-bit), as well as an Ubuntu setup on another computer.

It compiles fine on Ubuntu (using g++) without any complaints, but I get the following error when I try to compile on my Windows machine with 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

As far as I can tell, there's nothing special in the function (especially since it compiles fine on my Ubuntu-setup):

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;
}

In case it matters, here's the Matrix class:

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();
};

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

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

发布评论

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

评论(1

情泪▽动烟 2025-01-01 00:58:21

我的大胆猜测是,near 和/或 far 被定义为宏,可能是为了可以编译古老的 16 位 DOS/Windows 代码。

尝试在函数前添加 #undef close#undef far 看看是否有帮助。

My wild guess is that near and/or far are defined as macros, possibly so that ancient 16-bit DOS/Windows code can be compiled.

Try adding #undef near and #undef far before your function and see if that helps.

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