我想编写一个可以接收任何类型的两个的QList和QVector功能:C++函数嵌套模板
QList<int> iList;
QVector<int> iVector;
QList<double> dList;
QVector<double> dVector;
所有这些类型都必须支持调用
my_func(iList); my_func(iVector); my_func(dList); my_func(dVector);
我的解决方案
template <template <typename Elem> typename Cont>
void my_func(const Cont& cont)
{
qDebug() << cont.isEmpty();
Elem el = cont.first();
qDebug() << el;
}
未编译:
error C2988: unrecognizable template declaration/definition
这种模板函数的正确形式是什么?
'Cont :: value_type'应该是'typename Cont :: value_type'。 – Constructor
这里是一个错字:'my_func(const Cont&cont); {'。 – Constructor
@Constructor谢谢!固定。 – mockinterface