Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


C++ operator precedence

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I use an overloaded matrix class with overloaded output and multiplication operators
template <typename T> class Matrix {
friend ostream& operator<<<>(ostream&, Matrix&;
template <typename T> Matrix<Z> operator*(const Matrix<Z> &, const Matrix<Z> &;
Whenever I try to output the result of a multiplication
cout << (A*B) << endl;
i get an error
main.cpp:33: could not convert `operator*((&EI))'' to Matrix<cx> &''
matrix.h:215: in passing argument 2 of `operator<< ostream &, Matrix<Z> & [with Z = cx]''
What on earth is wrong with this? (gcc v2.95) thanking you ...

Share this post

Link to post
Share on other sites
Hard to tell with the gcc 2.95 error message. I expect it has to do with operator<< taking a non-const Matrix&.

Try changing the declaration of operator<< to something like

friend ostream& operator<<(ostream&, const Matrix&);

PS. Also try a newer compiler if possible eg gcc 3.3. Not only is it more standards compliant but a number of the template error messages are much better.


Philip Dunstan

Share this post

Link to post
Share on other sites
Thanks, that worked. I tried that originally but had problems because the << operator was calling my index operator (int,int) which can''t be const.

I''d love to use g++ 3.3. However the sysadmin tells me he doesn''t want to upgrade it because all the old fogies who haven''t got using namespace std; in their code will riot. Or something like that.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!