C++ 了解C+中运算符的范围+; #包括 名称空间Foo { 类Baz{}; std::ostream和操作员

C++ 了解C+中运算符的范围+; #包括 名称空间Foo { 类Baz{}; std::ostream和操作员,c++,function,namespaces,scope,argument-dependent-lookup,C++,Function,Namespaces,Scope,Argument Dependent Lookup,DRTL 编译器可以找到用户定义的operator@Kolyunya很高兴能帮上忙! #include <iostream> namespace Foo { class Baz { }; std::ostream& operator<< ( std::ostream& ostream , const Baz& baz ) { return ostream << "operator<

DRTL


编译器可以找到用户定义的
operator@Kolyunya很高兴能帮上忙!
#include <iostream>

namespace Foo
{
    class Baz { };   

    std::ostream& operator<< ( std::ostream& ostream , const Baz& baz )
    {
        return ostream << "operator<<\n";
    }
}

int main()
{
    std::cout << Foo::Baz();
}
 std::cout << Foo::Baz();
 operator<<(std::cout, Foo::Baz());
 std::operator<<(std::ostream&, /* all the builtin types and Standard strings and streams */)
 Foo::operator<<(std::ostream&, const& Baz)