Operator << overloading apparently not working.


The following code compiles, but does not "work". It's supposed to print

"There goes foo 0 1 2 3 4 "

but instead prints

"There goes foo "

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

class foo {
    public:
        int a;
        foo(){};
};

ostream& operator<<(ostream& output, const foo& p) {
    for (int i=0; i++; i< 5)
// This is not printing anything at all.
// It also returns the warning "3rd expression in for has no effect"
        output << i << " " ; 

    return output;
}

int main()
{
    foo p;
    cout <<"There goes foo  " << p;
    return 0;
}


Thanks a lot for the help in advance.
Recheck your for statement.
Does this seem correct to you??
for (int i=0; i++; i< 5)

If you still think it is right - then check here (halfway down about for loops)
http://www.cplusplus.com/doc/tutorial/control/
oh my god.. XD I stop programming c++ for 6 months and this happens to me.
Thank you so much.
Topic archived. No new replies allowed.