operator overloading

Discussion in 'C++' started by hannach, Apr 2, 2011.

  1. hannach

    hannach New Member

    Joined:
    Feb 4, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  2. michael j g

    michael j g New Member

    Joined:
    Nov 3, 2010
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Canteen at a school
    Location:
    SOUTH AUSTRALIA
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice