On Apr 20, 12:56 pm, Lionel B <m...@privacy.netwrote:
Quote:
The following code compiles ok and runs as expected:
Quote:
#include <iostream>
#include <iomanip>
Quote:
int main()
{
typedef std::ostream& (*manip_t)(std::ostream&);
Quote:
manip_t x = std::endl;
Quote:
if (x==static_cast<manip_t>(std::endl))
std::cout << "endl detected" << std::endl;
return 0;
}
Quote:
However, without the cast I get a compiler error:
>
main.cpp:10: error: assuming cast to type ?std::basic_ostream<char, std::char_traits<char& (*)(std::basic_ostream<char, std::char_traits<char&)? from overloaded function
Quote:
which I interpret as:
>
main.cpp:10: error: assuming cast to type ?std::ostream& (*)(std::ostream&)? from overloaded function
Quote:
main.cpp:10: error: assuming cast to type ?manip_t? from overloaded function
Quote:
But my standard library ref defines:
Quote:
template<typename CharT, typename Traitsbasic_ostream<CharT, Traits>& endl(basic_ostream< CharT, Traits >&)
Quote:
which also boils down to my manip_t...
If that were true, then your code wouldn't be legal. I'll bet
your manip_t is a type, and not a template.
Quote:
so why does my compiler seem to think an explicit cast is
necessary?
Because std::endl is a template, and it has to know which one to
instantiation.
--
James Kanze (Gabi Software) email:
james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34