Jestus
Jestus

Reputation: 635

"Expression must be a pointer to a complete object type"

I've tried browsing many of the other topics out there on this, but none of them seem to fix my specific problem.

I have a 3X3 matrix class and have the following code to allow the user to access the matrix's rows:

V3& M33::operator[](int i) 
{

  return rows[i]; // rows is a Vector3 array

}

Yet in my vector class when I try to do this:

void rotateAboutArbitraryAxis(int axis, float degrees)
{
    if(axis == 0)
    {
        M33 m();
        V3 row0(1.0f, 0.0f, 0.0f);
        V3 row1(0.0f, cos(degrees), -sin(degrees));
        V3 row2(0.0f, sin(degrees), cos(degrees));


        m[0] = row0; //error
        m[1] = row1; //error
        m[2] = row2; //error

    }

}

There is an error flagged in the three marked places above.

The intellisense tells me "Expression must be a pointer to a complete object type" while the actual build-error is "subscript requires array or pointer type."

Does anyone know why this is? I can provide more information if needed.

Thanks!

Upvotes: 0

Views: 8480

Answers (1)

R Sahu
R Sahu

Reputation: 206617

The line

    M33 m();

declares m to be a function that takes no arguments and returns a M33. That's crux of the most vesting parse.

Since the compiler thinks m is a function, it complains when you use it in the following lines:

    m[0] = row0; //error
    m[1] = row1; //error
    m[2] = row2; //error

As P0W commented, if you change the first line to:

    M33 m;

things should work as long as M33 defines the operator[] function.

Upvotes: 1

Related Questions