Udostępnij przez


Błąd kompilatora C3206

"function" : nieprawidłowy argument typu dla parametru, brak listy argumentów typu na typie klasy "typename"

Uwagi

Szablon funkcji jest definiowany jako argument typu szablonu. Przekazano jednak argument szablonu szablonu.

Przykłady

Poniższy przykład generuje C3206:

// C3206.cpp
template <class T>
void f() {}

template <class T>
struct S {};

void f1() {
   f<S>();   // C3206
   // try the following line instead
   // f<S<int> >();
}

Możliwe rozwiązanie:

// C3206b.cpp
// compile with: /c
template <class T>
void f() {}

template <class T>
struct S {};

void f1() {
   f<S<int> >();
}

C3206 może również wystąpić w przypadku używania typów ogólnych:

// C3206c.cpp
// compile with: /clr
generic <class GT1>
void gf() {}

generic <class T>
value struct GS {};

int main() {
   gf<GS>();   // C3206
}

Możliwe rozwiązanie:

// C3206d.cpp
// compile with: /clr
generic <class GT1>
void gf() {}

generic <class T>
value struct GS {};

int main() {
   gf<GS<int> >();
}

Szablon klasy nie jest dozwolony jako argument typu szablonu. Poniższy przykład zgłasza błąd C3206:

// C3206e.cpp
template <class T>
struct S {};

template <class T>
void func() {   // takes a type
   T<int> t;
}

int main() {
   func<S>();   // C3206 S is not a type.
}

Możliwe rozwiązanie:

// C3206f.cpp
template <class T>
struct S {};

template <class T>
void func() {   // takes a type
   T t;
}

int main() {
   func<S<int> >();
}

Jeśli parametr szablonu szablonu jest niezbędny, musisz opakowować funkcję w klasie szablonu, która przyjmuje parametr szablonu szablonu:

// C3206g.cpp
template <class T>
struct S {};

template<template<class> class TT>
struct X {
   static void func() {
      TT<int> t1;
      TT<char> t2;
   }
};

int main() {
   X<S>::func();
}