error

This is a discussion on error within the C++ Programming forums, part of the General Programming Boards category; I have this defined in my class Code: Matrix& operator^(int&); // in class Matrix Matrix& Matrix :: operator^(int n) { ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    1

    error

    I have this defined in my class
    Code:
    Matrix& operator^(int&); // in class Matrix
    
    Matrix& Matrix :: operator^(int n)
    {
    Matrix M = *this;
    for(int i=0; i<n-1; i++)
    	M = M * (*this);
    
    return M;
    }
    and i'm getting this error; error C2511: 'Matrix &Matrix:perator ^(int)' : overloaded member function not found in 'Matrix'

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Look at the argument. In your class declaration you have int&, but in the definition you only have int (no reference).

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You don't probably want to pass the argument by (non-const) reference, because this means you can't use the operator as:

    Code:
    Matrix m, n;
    n = m ^ 5;
    Also, you are returning a reference to a local, and operator ^ means XOR, not exponentiation.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

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