A
Ares Lagae
How is an output stream operator of a class nested in a class template
defined? The code fragment below does not compile. Maybe it's just me,
but I don't see why it should not compile.
Best regards,
#include <iostream>
template <typename T>
struct foo
{
struct bar {};
bar bar_;
const bar& get_bar() const { return bar_; }
};
template <typename Ch, typename Tr, typename T>
std::basic_ostream<Ch,Tr>& operator<<(std::basic_ostream<Ch,Tr>&
ostream, typename foo<T>::bar&)
{
return ostream;
}
int main()
{
foo<int> f;
const foo<int>::bar& b = f.get_bar();
std::cout << b << "\n";
}
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for
ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 21: error: no operator "<<" matches these
operands
operand types are: std:stream << const foo<int>::bar
std::cout << b << "\n";
^
1 error detected in the compilation of "ComeauTest.c".
defined? The code fragment below does not compile. Maybe it's just me,
but I don't see why it should not compile.
Best regards,
#include <iostream>
template <typename T>
struct foo
{
struct bar {};
bar bar_;
const bar& get_bar() const { return bar_; }
};
template <typename Ch, typename Tr, typename T>
std::basic_ostream<Ch,Tr>& operator<<(std::basic_ostream<Ch,Tr>&
ostream, typename foo<T>::bar&)
{
return ostream;
}
int main()
{
foo<int> f;
const foo<int>::bar& b = f.get_bar();
std::cout << b << "\n";
}
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for
ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 21: error: no operator "<<" matches these
operands
operand types are: std:stream << const foo<int>::bar
std::cout << b << "\n";
^
1 error detected in the compilation of "ComeauTest.c".