Not
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
"name" : beroende namn är inte en typ
Anmärkningar
Nyckelordet typename krävs om ett beroende namn ska behandlas som en typ. Lägg till typename i deklarationen för kod som fungerar på samma sätt i alla versioner av Visual C++.
Examples
I följande exempel genereras C4346:
// C4346.cpp
// compile with: /WX /LD
template<class T>
struct C {
T::X* x; // C4346
// try the following line instead
// typename T::X* x;
};
Följande visar andra exempel där nyckelordet typename krävs:
// 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
};
och detta,
// 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
};