The following code does not compile ( error: no matching function for call to
`<unnamed>::A::print(main()::B&) ):

#include <iostream>

namespace {
        struct A {
                template<class C> void print(C c)
                {
                        c.print();
                }
        };

}

int main()
{
        A a;
        struct B {
                void print()
                {
                        std::cout << "whee!";
                }
        };
        B b;
        a.print(b);
}

However, defining B in the same namespace as A, in a different namespace, or
even in the global namespace compiles and works as expected.  I don't know the
standard well enough to say if this is correct behavior, but it seems like an
odd rule.


-- 
           Summary: Function template can find a struct in same
                    namespace/other namespace but not inside a function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mlybbert at users dot sourceforge dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39770

Reply via email to