By following this site C++ FAQ I have overloaded an operator() for my Matrix class. This is my class:
class Matrix
{
public:
inline float& operator() (unsigned row, unsigned col)
{
return m[row][col];
}
private:
float m[4][4];
};
now I can use it in main function like this:
int main()
{
Matrix matrix;
std::cout << matrix(2,2);
}
but now I want to use it with the pointer like this:
int main()
{
Matrix matrix;
Matrix* pointer = &matrix;
std::cout << pointer(2,2);
}
and compilator tells that pointer can not be used as a function. Is there any solution?
You’ll either need to dereference it:
Or you’ll need to call the operator by its full name: