В следующей программе я ожидаю, что it::type
будет удвоено.Вместо этого я получаю сообщение об ошибке компилятора it is not a class, namespace, or enumeration
.Основываясь на других ответах stackoverflow на подобные вопросы, эти ошибки, как правило, видны, если вы не создаете экземпляр шаблона с аргументами.Я думаю, что делаю это правильно.Может кто-нибудь объяснить, в чем может быть ошибка в следующем коде?
#include <iostream>
#include <tuple>
using namespace std;
template <typename ...Ts>
struct list {};
template <int I, typename T, typename ...Ts>
struct S {
using type = typename S<I-1, Ts...>::type;
};
template <typename T, typename ...Ts>
struct S<0, T, Ts...> {
using type = T;
};
template <int I, typename ...Ts>
S<I, Ts...> ith(list<Ts...>) {
return S<I, Ts...>{};
}
int main() {
auto l = list<const char *, void *, double>{};
S<2, const char*, void *, double> it = ith<2>(l);
it::type a = 1; // This line seems to cause the issue,
// if removed the program compiles fine.
return 0;
}
Error:
p.cpp:32:2: error: 'it' is not a class, namespace, or enumeration
it::type a = 1;
^
p.cpp:31:36: note: 'it' declared here
S<2, const char*, void *, double> it = ith<2>(l);
^
1 error generated.