473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Error using cout in conjunction with a class method

1
During compilation, I get a slew of errors whenever I perform
this operation:

Expand|Select|Wrap|Line Numbers
  1. cout << aMatrix.Transpose( ) << endl;
  2.  
-- the overloaded operator<< non-member method is:
Expand|Select|Wrap|Line Numbers
  1.        ostream & operator<<( ostream & out, const Matrix & matrixRHS )
  2.  
-- the member method Transpose( ) [ transposes the calling object by
moving values into a temp Matrix object and then assignin it to the
calling object] is:

Expand|Select|Wrap|Line Numbers
  1.      void Transpose( void );
  2.  
-- errors: [including quite a few more it won't let me post but they all
deal with the << operator]
Expand|Select|Wrap|Line Numbers
  1. Test.cpp:32: error: no match for ‘operator<<’ in ‘std::cout << aMatrix. Matrix::Transpose()’
  2. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
  3. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:78: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
  4. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:90: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
  5. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:125: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
  6.  

However, the code functions correctly with this set of commands:

Expand|Select|Wrap|Line Numbers
  1. aMatrix.Transpose( ) ;
  2. cout << aMatrix << endl;
  3.  
Does anyone have any idea as to why the first method produces so many errors concerning the ostream << operator? I thought it may have something to do with the const-ness of the method but I am not allowed to change the Transpose( ) method so that it returns a const Matrix object. Anybody have any input?
Oct 8 '06 #1
1 2456
Banfa
9,065 Expert Mod 8TB
As well as the normal operations available you have added an overload for the cout << operator to accept a const Matrix &.

However the Transpose function is defined as

void Matrix::Transpose( void );

so in this line of code

cout << aMatrix.Transpose( ) << endl;

you are passing the type void to cout <<. Since there is no override for void an(or several) error ensues.

However in this code

aMatrix.Transpose( )
cout << aMatrix << endl;

You call the tranpose function and then pass the matrix to cout << and it can use the overloaded operator you have defined.
Oct 9 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: sks_cpp | last post by:
I am trying to wrap the map iterator for keys and values. However, I seem to run into problems with the values for const_iterator - it works for all other combinations. Below I list my code and...
3
by: Materialised | last post by:
I am having some issues with the following code, basically what I am trying to do, is familierise myself with compiler warnings, when I try to access a private or protected class function. Here is...
7
by: kk | last post by:
Hi Guys, i am posting a cpp program contains runtime error, memory not allocated to char *x in class B. while accessing showx function it doesn't print values. if anybody knows send a reply plz....
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
3
by: Baby Lion | last post by:
hi,everyone , one Runtime error occur when running , maybe it's about assigning memory . I need your help , thanks. It's about the travelling sellman problem . //#include "stdafx.h" ...
4
by: elShazo | last post by:
I am getting this error on compile "expected unqualified-id at end of input". Here is the block of code that generates the error: /* Proxy unmountSource I/O */ /* Method unmountSource */...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
2
by: Latina | last post by:
Hi I am doing a program oveloraded operator. I am having a few errors on it. Error1: request for member `insertElement' in `S1set', which is of non- class type `IntegerSet' Error2: no...
2
by: Latina | last post by:
Hi I am doing a program overloaded operator. I am having a few errors on it. Error1: request for member `insertElement' in `S1set', which is of non- class type `IntegerSet' Error2: no matching...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.