Encountering weird errors when trying to overload the ostream operators

Hi all.
I am trying to overload the ostream operator << and am encountering a bunch of problems when I'm trying to do that...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>

using namespace std;

class OstreamHelp
{
    private:
    ostream& (*_func)(ostream&, int);
    int _arg;
    public:
    OstreamHelp(ostream& (*func)(ostream&, int), int arg) :
    _func(func), _arg(arg)
    { }
    friend ostream& operator<<(ostream& ost, OstreamHelp& hlp);
};

ostream& operator<<(ostream& ost, OstreamHelp& hlp)
{
    return hlp._func(ost, hlp._arg);
}

ostream& myEndlHelp(ostream& ost, int n)
{
    for(int i=0; i<n; i++)
    {
        ost<<endl;
    }
}

OstreamHelp myEndl(int n)
{
    return OstreamHelp(&myEndlHelp, n);
}


ostream& myEndl(ostream& os)
{
    os<<"\n";
    return os;
}
int main(int argc, char** argv)
{
    cout<<"End line with parameterless manipulator \"myEndl()\""<<myEndl;
    cout<<"Insert 3 \\n's with manipulator \"myEndl(int)\""<<myEndl(3);
    return 0;
}


If I try to compile this, I get:

C:\Programmieren\Projects\test\streamtest>mingw32-g++ ostreammanipulator.cpp -o
Ostream
ostreammanipulator.cpp: In function 'int main(int, char**)':
ostreammanipulator.cpp:44: error: no match for 'operator<<' in 'std::operator<<
[with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_tra
its<char> >&)(& std::cout)), ((const char*)"Insert 3 \\n\'s with manipulator \"m
yEndl(int)\"")) << myEndl(3)'
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:108: not
e: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostr
eam<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:117: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_Cha
rT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:127: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char,
 _Traits = std::char_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:165: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_trait
s<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:169: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::c
har_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:173: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<ch
ar>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/ostream.tcc
:91: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostre
am<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::c
har_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:180: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::
char_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/ostream.tcc
:105: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostr
eam<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_t
raits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:191: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_t
raits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:200: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_
traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:204: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = s
td::char_traits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:209: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<
char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:213: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<c
har>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:221: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_tr
aits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:225: not
e:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_Char
T, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_tr
aits<char>]
c:\programmieren\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/ostream.tcc
:119: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostr
eam<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _
CharT = char, _Traits = std::char_traits<char>]
ostreammanipulator.cpp:17: note:                 std::ostream& operator<<(std::o
stream&, OstreamHelp&)



I don't really understand what's going on, so help would be appreciated.
Topic archived. No new replies allowed.