Всем привет. Есть такой код (nested.cpp):
#include <iostream>
#include <string>
#include <sstream>
class base_exception
{
public:
template <class E> friend E const& operator<<(E const& ex, std::string const& str)
{
ex.m_what += str;
return ex;
}
std::string const& what() const
{
return m_what;
}
private:
mutable std::string m_what;
};
class module_error : public base_exception
{
public:
class bad_config;
};
class module_error::bad_config : public module_error
{
};
int main()
{
module_error::bad_config err;
err << "module_error::bad_config" << " test"; // строка 34
std::cout << err.what() << std::endl;
return 0;
}
На gcc 4.6.2 всё работает, Visual Studio 12 2013 выдает ошибку компиляции:
Microsoft (R) Build Engine version 12.0.21005.1
[Microsoft .NET Framework, version 4.0.30319.18444]
...
nested.cpp(34): error C2676: binary '<<' : 'module_error::bad_config' does not define this operator or a conversion to a type acceptable to the predefined operator
Можно ли это как-то побороть?