Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,110
77
Solon, OH
Okay. I have 2 classes, Complex and Complex2 (which inherits from Complex). I defined the << and >> operators for Complex2 objects, but when I try to use them in my main code the compiler complains.

Relevant code from Complex2.cpp:
Code:
// takes a reference to the current stream
// returns reference to the stream
// adds output to the stream for use with cout, etc.
ostream& Complex2::operator<< (ostream& stream)
{
    stream << real << "+" << imag << "i";
    return stream;
}

// takes a reference to the current stream
// returns reference to the stream
// adds what we want to print to the stream for use with cin, etc. 
istream& Complex2::operator>> (istream& stream)
{
    char plusSign, imagSign; // Used to read throw-away plus sign and trailing i
    stream >> real >> plusSign >> imag >> imagSign;
    return stream;
}
And the code from main.cpp that uses it:
Code:
cout << "All Complex Numbers" << endl;
        cout << cplxNumbers[0] << endl;
        cout << cplxNumbers[1] << endl;
The compiler spits out the following error messages:
Code:
Building target “CIS340-1” of project “CIS340-1” with configuration “Debug” — (3 errors)
        cd /Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1
    /usr/bin/gcc-4.0 -x c++ -arch i386 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -g -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -mfix-and-continue -mmacosx-version-min=10.4 -fvisibility-inlines-hidden -I/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/build/CIS340-1.build/Debug/CIS340-1.build/CIS340-1.hmap -F/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/build/Debug -I/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/build/Debug/include -I/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/build/CIS340-1.build/Debug/CIS340-1.build/DerivedSources -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c /Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp -o /Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/build/CIS340-1.build/Debug/CIS340-1.build/Objects-normal/i386/main.o
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp: In function 'void createComplexNumber()':
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp:18: error: no match for 'operator>>' in 'std::cin >> cplxNumbers[cplxIndex]'
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:134: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:137: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:169: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:172: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:175: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:178: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:181: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:187: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:191: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:194: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:198: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:201: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:204: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:207: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:230: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp: In function 'int parseMainInput(char)':
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp:91: error: no match for 'operator<<' in 'std::cout << cplxNumbers[0]'
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:159: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:102: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:176: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:187: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:191: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:202: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:183: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:218: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:242: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:217: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:265: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:288: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:311: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
/Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp:92: error: no match for 'operator<<' in 'std::cout << cplxNumbers[1]'
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:159: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:102: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:176: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:187: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:191: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:202: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:183: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:218: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:242: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:217: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:265: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:288: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:311: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
        /Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp:18: error: no match for 'operator>>' in 'std::cin >> cplxNumbers[cplxIndex]'
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:134: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:137: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:169: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:172: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:175: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:178: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:181: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:187: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:191: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:194: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:198: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:201: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:204: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:207: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/istream:230: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
        /Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp:91: error: no match for 'operator<<' in 'std::cout << cplxNumbers[0]'
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:159: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:102: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:176: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:187: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:191: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:202: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:183: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:218: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:242: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:217: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:265: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:288: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:311: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
        /Users/wrldwzrd89/Documents/Computers/Programming/Projects/CIS340-1/main.cpp:92: error: no match for 'operator<<' in 'std::cout << cplxNumbers[1]'
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/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>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:159: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:102: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:176: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:187: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:191: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:202: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:183: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:218: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:242: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/ostream:217: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:265: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:288: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
        /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/ostream.tcc:311: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
Build failed (3 errors)
 

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,110
77
Solon, OH
Problem solved. Evidently, overloaded << and >> operators have to be global functions, not class members.:eek: As soon as I made that change, and fixed the compiler error about >> and << requiring 2 arguments it worked.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
This is yet another reason why I think C++ is a horribly designed language.

Take this example:
Code:
ostream &MyClass::operator << (osstream & stream) {
    // ...
}

You won't be able to call this method. You need to declare the function like this:

Code:
ostream& operator << (ostream& os, const MyClass& s) {
    // ...
}

Notice that this isn't a method declared on MyClass. It's a function declared in the global scope. When declared like this, you can call it like this:

Code:
stream << instanceOfMyClass;

If you need to access private ivars, you can declare the method as a friend of MyClass.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
Operator overloading is evil. (tm)

only when people are bad designers. it rocks when used appropriately.

i'm working in Flex these days, and i'm rather annoyed there's no operator overloading. e.g. this:
Code:
if (date1 == date2)
... compares pointers. not terribly useful. i'd like to overload it to compare values.
 

charray

macrumors newbie
Sep 10, 2007
11
0
Besides making it global, you can also consider making use of the friend keyword and keep the function in the class. The function signature would be similar. The plus side is your operator code can access private variables of the class.

Operator Overloading is not evil. Imagine we have to distinguish classes (equal() comparison) and primitive values (== comparison). It is indeed more messy and unreadable. :D
 

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,110
77
Solon, OH
Besides making it global, you can also consider making use of the friend keyword and keep the function in the class. The function signature would be similar. The plus side is your operator code can access private variables of the class.

Operator Overloading is not evil. Imagine we have to distinguish classes (equal() comparison) and primitive values (== comparison). It is indeed more messy and unreadable. :D
Yes, that's exactly what I ended up doing. Only problem now is that the compiler can't find a match for my use of the = operator, which I've also overloaded.:( I'm bound and determined to get this working...

EDIT: I got it, finally.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Problem solved. Evidently, overloaded << and >> operators have to be global functions, not class members.:eek: As soon as I made that change, and fixed the compiler error about >> and << requiring 2 arguments it worked.

Not quite. If you want an operator stream << complex, you have the choice of either defining a global function operator<< (stream, complex) as you did, or a member of the stream class stream::eek:perator<< (complex). To be able to use a member function, it must be a member of the class corresponding to the first operand.

In this case, since you shouldn't modify the stream classes, you'll have to use a global function.
 

wrldwzrd89

macrumors G5
Original poster
Jun 6, 2003
12,110
77
Solon, OH
Not quite. If you want an operator stream << complex, you have the choice of either defining a global function operator<< (stream, complex) as you did, or a member of the stream class stream::eek:perator<< (complex). To be able to use a member function, it must be a member of the class corresponding to the first operand.

In this case, since you shouldn't modify the stream classes, you'll have to use a global function.
That makes sense. What you described is pretty much what I ended up doing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.