Overloaded () and inheritance
Hi. I'm having a problem with using an overloaded () operator in a class derived from that containing it. I have a template matrix class defined that works with no problems, and uses an overloaded () operator to access elements of it. However, my Vec2D class that inherits from the matrix will not allow me access to the () operator already defined.
Vec2D(const vType x = 0, const vType y = 0) : Matrix<vType>(1,2) {
(0,0) = x;
(0,1) = y;
}
All other aspects of this class and inheritance etc are working, since when I change to an implicit setValue() function, the class works as expected.
This is my () function.
mType& Matrix::operator()(const int i, const int j) {
int a = j * ysize;
return values[a+i];
}
I've tried all sorts of things using the scope operator, and scoured google over and over and got nowhere.
Please help!
Simon
PS. Dev-CPP 4.9.9.2
# 1 Re: Overloaded () and inheritance
Vec2D(const vType x = 0, const vType y = 0) : Matrix<vType>(1,2) {
operator()(0,0) = x;
operator()(0,1) = y;
}
You can only invoke an operator function by symbol if the compiler has some contexxt to work with. In your original, the parentheses were just that: parentheses. For operator() to be invoked, the compiler needs to see what looks like a function call. In the absence of that context, you have to spell out the operator's function name in full.