Jibb Smart
Jibb Smart

Reputation: 315

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

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

Upvotes: 2

Views: 1468

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254461

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.

Upvotes: 7

Related Questions