quick c++ operator question

This is a discussion on quick c++ operator question within the C++ Programming forums, part of the General Programming Boards category; my prof gave me this stub for an operator: MySquarMatrix operator +(const MySquareMatrix &, const MySquareMatrix &); { // add ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    25

    quick c++ operator question

    my prof gave me this stub for an operator:

    MySquarMatrix operator +(const MySquareMatrix &, const MySquareMatrix &);
    {
    // add matrices a+b
    }

    MySquareMatrix is the name of the class, but this operator is not a member function

    question 1) is the MySquareMatrix that is listed first in the operator the return type?

    2) do i define what a+b equals in this operator, or do i
    just define the '+'? (if that makes sense) i guess i just want to know what would go in the definition.

    thanks
    I Love Jesus

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    1) yes
    2) no, that is just a prototype. That is the declaration, not the definition, as it ends with a semicolon, and the arguments are unnamed.

    just like you would define it like this

    MySquareMatrix operator +(const MySquareMatrix a&, const MySquareMatrix b&) {
    MySquareMatrix result;
    // do some matrix calcs that I don't know
    return result
    }
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    25
    can i call member functions in the definition of the operator?
    I Love Jesus

  4. #4
    edwardtisdale
    Guest

    Thumbs up re:can i call member functions in the definition of the operator?

    As long as that function has information that an object has been created using the class containing the member functions then yes,
    by naming the object.memberfunction . Does this answer your question?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 11:33 AM
  2. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 05:51 PM
  3. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 10:06 AM
  4. Quick Sort Help
    By NavyBlue in forum C Programming
    Replies: 1
    Last Post: 03-02-2003, 10:34 PM
  5. Replies: 0
    Last Post: 04-30-2002, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21