operator overloading

hannach's Avatar, Join Date: Feb 2011
Newbie Member
I write class Matrix, and I want to overloading the operator [][].
The prototype of this functin is:
Code:
double& Matrix::operator [][](int row,int col)
I get some errors:
Code:
error C2270: '[]' : modifiers not allowed on nonmember functions
error C2092: '[]' array element type cannot be function
error C2470: 'Matrix::[]' : looks like a function definition, but there is no parameter list; skipping apparent body
I can't understand what the problem, any suggestions?
0
michael j g's Avatar
Go4Expert Member
well if you are useing c++ you can right click on the error and then click go to line or what ever it says.
you will find it may be on one of three lines.

Middle
line up
line down

Exaple

#include (iostream)
#include (string)

using name space std;
int main () //error above this line "name space"
{ //error on this line "{"
// what ever gos in this area

] // error on this line "]"


this is not the exact words that errors say it is just a way of showing errors and some positions of them.

i wish you luck with you program.