Overloading operator() and getting "lvalue required as unary '&' operand"

Viewed 41

I have a matrix class for which I am overloading the operator() to access its (row, column) values.

Here is a synthesized version of the class header:

template<typename T>
class mat4
{
  public:
    T m[4][4];
...
    T  operator()(int i, int j) const;
    T& operator()(int i, int j);
...

}

and its implementation:

...

template<typename T>
T mat4<T>::operator()(int i, int j) const
{
  return m[i][j];
}

template<typename T>
T& mat4<T>::operator()(int i, int j)
{
  return m[i][j];
}
...

I am trying to pass the first index of this array as the last argument to the function glUniformMatrix4fv, but if I use the following syntax:

glUniformMatrix4fv(glGetUniformLocation(ID, uniformName.c_str()), 1, GL_TRUE, &data(0,0));

I get the error "lvalue required as unary '&' operator". The way I've been able to get around this was to access the m member variable directly, through:

glUniformMatrix4fv(glGetUniformLocation(ID, uniformName.c_str()), 1, GL_TRUE, &data.m[0][0]);

but I'd like to know if there's a way around this using the overloaded operator directly.

Many thanks in advance.

0 Answers
Related