Matthew
Matthew

Reputation: 850

error: expected primary-expression before 'float'

I am having some odd behavior from two of my functions. both are erroring when they are getting called in the build process. I am not to sure what it is I am missing as everything looks fine to me but that is obviously not the case.

First line with the error:

matf4x4 perspective = perspective(m_fov, m_aspect, m_near, m_far); // ERROR (1)

Perspective function definition:

static mat4x4<float> perspective(float fov, float aspect, float n, float f) {
    float q = 1.0f / tanf(radians(0.5f * fov));
    float A = q / aspect;
    float B = (n + f) / (n - f);
    float C = (2.0f * n * f) / (n - f);

    mat4x4<float> result;

    result[0] = vec4f(A, 0.0f, 0.0f, 0.0f);
    result[1] = vec4f(0.0f, q, 0.0f, 0.0f);
    result[2] = vec4f(0.0f, 0.0f, B, -1.0f);
    result[3] = vec4f(0.0f, 0.0f, C, 0.0f);

    return result;
}

ERROR (1) output:

C:\Users\Matt\CLionProjects\SkyGames\Engine\Camera\Camera.cpp:18:66: error: no match for call to '(sky::matf4x4 {aka sky::mat4x4<float>}) (float&, float&, float&, float&)'
  matf4x4 perspective = perspective(m_fov, m_aspect, m_near, m_far);

Second line with error:

matf4x4 lookat = lookat<float>(m_position, centre, m_up); // ERROR (2)

Lookat function definition:

template <typename T>
static mat4x4<T> lookat(const vec3<T>& eye, const vec3<T>& centre, const vec3<T>& up) {
    vec3<T> f = normalize(centre - eye);
    vec3<T> upN = normalize(up);
    vec3<T> s = cross(f, upN);
    vec3<T> u = cross(s, f);
    mat4x4<T> M = mat4x4<T>(vec4<T>(s[0], u[0], -f[0], T(0)),
                            vec4<T>(s[1], u[1], -f[1], T(0)),
                            vec4<T>(s[2], u[2], -f[2], T(0)),
                            vec4<T>(T(0), T(0), T(0), T(1)));
    return M * translate<T>(-eye);
}

Matrix 4x4 float with operator overload =

mat4x4<T>&operator=(const mat4x4<T>& mat) {
    for (int i = 0; i < m_width; ++i)
        matrix[i] = mat.matrix[i];
    return *this;
}

ERROR(2) output:

C:\Users\Matt\CLionProjects\SkyGames\Engine\Camera\Camera.cpp:20:26: error: expected primary-expression before 'float'
  matf4x4 lookat = lookat<float>(m_position, centre, m_up);

Upvotes: 0

Views: 8613

Answers (1)

lazyplayer
lazyplayer

Reputation: 393

Change variable name or function name.

In statement matf4x4 lookat = lookat<float>(...); , the compiler first add variable lookat to its symbol table, so outer layer function lookat is hidden in current scope. When meet the second lookat, the compiler think it's the variable lookat.

Upvotes: 1

Related Questions