Need a quick example! Operator overloading and matrix

This is a discussion on Need a quick example! Operator overloading and matrix within the C++ Programming forums, part of the General Programming Boards category; So i have a matrix that is [2][2], and i want to be able to have: [cody] Matrix a(1, 2, ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    Need a quick example! Operator overloading and matrix

    So i have a matrix that is [2][2], and i want to be able to have:
    [cody]
    Matrix a(1, 2, 3, 4); //a = [2][2] - 1, 2, 3, 4
    Matrix b(4, 3, 2, 1; //b = [2][2] - 4, 3, 2, 1
    Matrix c;

    c = a + b;
    [/code]

    I have (summed up):
    Code:
    class Matrix
    {
    public:
        Matrix();
        Matrix(double a, double b, double c, double d);
        Matrix operator + (Matrix first);
    private:
        //the matrix, etc
    };
    
    Matrix::Matrix operator + (Matrix& a)
    {
    
    
    }

    I don't know how to implement it, no tutorial i can find explains it well enough to me. I don't see how i can only pass one object and what to return....

    What it needs to do is:
    Code:
    | 1  2  |        | 4  3 |         | 5   5 |
                   +                = 
    | 3  4  |         |2   1|          |5   5 |

    Can anyone help me out quick? Thanks.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    >>(summed up)<<

    post the whole thing...we need to see how you handled the overloaded "+"

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Operator overloading question

    Don't re-post a question that has been answered and you either haven't looked or haven't bothered asking for further details on. If you still want the question answered, go back to your old thread and say "I still don't get it, can someone explain (some part that you're having trouble on) better?".
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 04:57 PM
  3. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-13-2004, 11:19 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM

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