![[Dept of Engineering]](http://www.eng.cam.ac.uk/images/house_style/engban-s.gif)
Error 226: "set1.cc", line 16 # No appropriate function found for call of
'operator <<'. Last viable candidate was "ostream &ostream::operator
<<(char)" ["/opt/aCC/include/iostream/iostream.h", line 509]. Argument of
type 'class set<int,less<int>,allocator>' could not be converted to
'char'.
cout << "s1 = " << s1;
^^^^^^^^^^^^^^^^^^^^^
The ^^^^ symbols show which part of the line is at fault. In this
case the compiler can't narrow down the problem, so next read the first
(easiest) part of the error message. There's something wrong with the
use of <<. Remember that in C++ many functions can be invoked by
an operator - it all depends on the number and type of operands. In
this case s1 (a set) isn't something that there's a matching function
for - hence the error message. The compiler, trying to be helpful,
gives the next best option -
a function tied to << that can deal with a char.
Another example: the line double d = sqrt(4); produces the
following error
because the integer given to sqrt has to be promoted to
a real, but the compiler doesn't know what kind of real.
Error 225: "foo.cc", line 6 # Ambiguous overloaded function call; more than
one acceptable function found. Two such functions that matched were "long
double sqrt(long double)" ["/opt/aCC/include/cmath", line 107] and "float
sqrt(float)" ["/opt/aCC/include/cmath", line 57].
<' is used in #include lines,
cout, in template definitions as well as meaning 'less-than'.
This makes deciphering declarations hard. c++decl can
sometimes help.
String s;
String s("initial");
String s();
cout << "Type a character: "; cin >> ch; cout << "Type a string: "; cin.getline(str,20);you're likely to get an empty string because the
>> operator
leaves the typed newline in the input stream. One way round this is to
use istream::ignore(INT_MAX, '\n');.