元编程,错误数量的模板参数
Metaprogramming, wrong number of template arguments
我正在尝试C 元编程。我有一个打字机类,其中包含头部类型和尾巴类型,该类型是列表末尾的另一种打字机或nulltype。
我也有一个IntegerList类,它是整数上的指针列表(嗯,这是一个记录系统,但是我尽可能地删除了代码,并且Integer* elements替换了Logger* Elements)
)我的文件不会编译,因为G 抱怨我使用的是"错误的模板参数(1,应为2)",而我不明白为什么。
我在哪里做错了?我只是从我信任的网站上复制了一些代码,它应该起作用...我主要决定使用元编程,因为这似乎是一件非常相关的事情,但是我已经开始失去我的思想^^。<<<<
预先感谢您。
ps。我有一个我无法更改的非常旧的G 编译器(2006),但是2013年的另一个G 给了我同样的错误。
PS2。我认为这种感冒不会汇编,因为整数不是一类,但是我在真实的课程中遇到了同样的错误,所以我相信我的错误在检查之前就会发生。
integerlist.hpp:
#include <list>
typedef int Integer;
class NullType
{
};
template<class H, class T>
class TypeList
{
typedef H Head;
typedef T Tail;
};
template<class T>
struct IntegerList : public std::list<Integer*>
{
};
template<>
struct IntegerList<NullType> : public std::list<Integer*>
{
};
template <class H, class T>
struct IntegerList<TypeList<typename H, typename T> > : public std::list<Integer*>
{ // ^ error right there
typedef TypeList<typename H, typename T> List_t;
typedef typename H Head_t;
typedef typename T Tail_t;
IntegerList()
{
push_back( new Head_t );
IntegerList<Tail_t> tmp;
merge( tmp );
}
~IntegerList()
{
IntegerList<List_t>::iterator it;
for ( it=begin(); it!=end(); ++it )
delete *it;
}
};
main.cpp:
#include "IntegerList.hpp"
int main(int argc, char **argv)
{
// wrong number of template arguments (1, should be 2)
IntegerList<TypeList<Integer, NullType> > mylist;
}
问题似乎是您在IntegerList
和TypeList
的使用情况下撒了几个typename
s。以下编译:
template <class H, class T>
struct IntegerList<TypeList< H, T> > : public std::list<Integer*>
{
typedef TypeList< H, T> List_t;
typedef H Head_t;
typedef T Tail_t;
. . .
}
完整示例http://coliru.stacked-crooked.com/a/5086e3015dc12ea0
相关文章:
- 模板元编程:如何将参数包组合成新的参数包
- 如何将可变参数模板转换为多个单个模板?(C++竞争编程调试模板)
- 如何使用可变参数模板类使用模板元编程获得最大值
- C++ 模板元编程:从模板模板参数继承
- 递归模板参数包编程
- 使用C++元编程提取 C 函数的参数("Practical C++ Metaprogramming" 中的示例)
- 在泛型编程中选择类型参数
- 我希望通过使用模板元编程从变量ARGS中进行剥离参数
- 将参数编程到对象数组
- 检测一个可以使用模板元编程可以采用的函数的最大参数数量
- 元编程,错误数量的模板参数
- 模板元编程:参数包中的模板参数数量错误
- template元编程:将一堆模板参数相乘
- C++模板编程/STL 推导参数
- argc C++中的argv参数(游戏编程)
- Cc 套接字编程 select() 的第一个参数
- C++组合参数模板元编程
- C++和混合编程中指针的默认参数
- Execlp()不接受参数列表,只接受命令.UNIX/LINUX编程
- Clang 无法使用模板元编程编译参数包扩展