C++ error 'overloaded-function'

Started by
1 comment, last by Zahlman 17 years, 11 months ago
What means this? error C2679: binary '>>': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) //declared variables: string accountNumber; char code; int gallons; double cost; int i; ifstream in; in >> accountNumber >> code >> gallons >>endl; // ERROR for this line
Advertisement
Could it be that you are putting a >> endl?

That does not make any sence. Why are you trying to set endl?
You can't "read into endl". It says there is "no overload for this type" because the reason you can't "read into endl" is that endl is an identifier (a global identifier in the std namespace that gets pulled in via the iostream header), not a keyword; and the type of that variable is a type X for which operator<<(istream&, X&) is not defined. It says "overloaded-function" as the type because 'endl' is actually the name of a function, rather than an ordinary variable. The ostream implementation provides for operator>>(ostream&, ostream&(*)(ostream&)&), where that second parameter refers to the type of the function pointer named by 'endl'. It could be implemented something like:

ostream& operator>>(ostream& os, ostream&(*pf)(ostream&)&) {  return pf(os);}


That is, you can do "std::endl(std::cout);" and it would have the same effect as "std::cout << std::endl;", because that is what endl is.

Anyway, if you want to skip to the next line, look up cin.ignore() and have fun.

This topic is closed to new replies.

Advertisement