Compilerwarnung (Ebene 1) C4346

'Name': Abhängiger Name ist kein Typ.

Der Typname Schlüsselwort (keyword) ist erforderlich, wenn ein abhängiger Name als Typ behandelt werden soll. Fügen Sie für Code, der in allen Versionen von Visual C++ gleich funktioniert, der Deklaration hinzu typename .

Im folgenden Beispiel wird C4346 generiert:

// C4346.cpp
// compile with: /WX /LD
template<class T>
struct C {
   T::X* x;   // C4346
   // try the following line instead
   // typename T::X* x;
};

Die folgenden Beispiele zeigen weitere Beispiele, in denen die typename Schlüsselwort (keyword) erforderlich ist:

// C4346b.cpp
// compile with: /LD /W1
template<class T>
const typename T::X& f(typename T::Z* p);   // Required in both places

template<class T, int N>
struct L{};

template<class T>
struct M : public L<typename T::Type, T::Value>
{   // required on type argument, not on non-type argument
   typedef typename T::X   Type;
   Type f();   // OK: "Type" is a type-specifer
   typename T::X g();   // typename required
   operator typename T::Z();   // typename required
};

und dies,

// C4346c.cpp
// compile with: /LD /WX
struct Y {
   typedef int Y_t;
};

template<class T>
struct A {
   typedef Y A_t;
};

template<class T>
struct B {
   typedef /*typename*/ A<T>::A_t B_t;   // C4346 typename needed here
   typedef /*typename*/ B_t::Y_t  B_t2;   // typename also needed here
};