Export (0) Print
Expand All
Expand Minimize

Compiler Error C3771

Visual Studio 2008
"identifier" : friend declaration cannot be found in the nearest namespace scope

The class template declaration for the specified template identifier cannot be found within the current namespace.

To correct this error

  • Ensure that the class template declaration for the template identifier is defined in the current namespace or that the template identifier is a fully-qualified name.

The following code example declares a class template and function in namespace NA, but attempts to declare a friend function template in namespace NB.

// C3771.cpp 
// compile with: /c

namespace NA {
template<class T> class A {
    void aFunction(T t) {};
    };
}
// using namespace NA;
namespace NB {
    class X {
        template<class T> friend void A<T>::aFunction(T); // C3771
// try the following line instead
//      template<class T> friend void NA::A<T>::aFunction(T);
// or try "using namespace NA;" instead.
    };
}

Community Additions

ADD
Show:
© 2014 Microsoft