L
Lionel B
The following code compiles ok and runs as expected:
#include <iostream>
#include <iomanip>
int main()
{
typedef std:
stream& (*manip_t)(std:
stream&);
manip_t x = std::endl;
if (x==static_cast<manip_t>(std::endl))
std::cout << "endl detected" << std::endl;
return 0;
}
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
which I interpret as:
main.cpp:10: error: assuming cast to type ‘std:
stream& (*)(std:
stream&)’ from overloaded function
ie.
main.cpp:10: error: assuming cast to type ‘manip_t’ from overloaded function
But my standard library ref defines:
template<typename CharT, typename Traits> basic_ostream<CharT, Traits>& endl(basic_ostream< CharT, Traits >&)
which also boils down to my manip_t... so why does my compiler
seem to think an explicit cast is necessary?
#include <iostream>
#include <iomanip>
int main()
{
typedef std:
manip_t x = std::endl;
if (x==static_cast<manip_t>(std::endl))
std::cout << "endl detected" << std::endl;
return 0;
}
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
which I interpret as:
main.cpp:10: error: assuming cast to type ‘std:
ie.
main.cpp:10: error: assuming cast to type ‘manip_t’ from overloaded function
But my standard library ref defines:
template<typename CharT, typename Traits> basic_ostream<CharT, Traits>& endl(basic_ostream< CharT, Traits >&)
which also boils down to my manip_t... so why does my compiler
seem to think an explicit cast is necessary?