我尝试使用模板来定义一些类,如下所示:
。H
template <class T>
class QVecTemp
{
public:
static QVector<QVector<T>> SplitVector<T>(QVector<T>, int);
private:
};
.cpp
#include "QVecTemp.h"
template <class T>
QVector<QVector<T>> QVecTemp::SplitVector<T>(QVector<T> items, int clustNum)
{
QVector<QVector<T>> allGroups = new QVector<QVector<T>>();
//split the list into equal groups
int startIndex = 0;
int groupLength = (int)qRound((float)items.count() / (float)clustNum);
while (startIndex < items.count())
{
QVector<T> group = new QVector<T>();
group.AddRange(items.GetRange(startIndex, groupLength));
startIndex += groupLength;
//adjust group-length for last group
if (startIndex + groupLength > items.count())
{
groupLength = items.Count - startIndex;
}
allGroups.Add(group);
}
//merge last two groups, if more than required groups are formed
if (allGroups.count() > clustNum && allGroups.count() > 2)
{
allGroups[allGroups.count() - 2].append(allGroups.last());
allGroups.remove(allGroups.count() - 1);
}
return (allGroups);
}
在static QVector<QVector<T>> SplitVector<T>(QVector<T>, int);
我收到以下错误:
错误:嵌套模板参数列表中的“>>”应该是“> >”
错误:预期的';' 在成员声明结束时
错误:“<”标记之前的预期不合格 ID
究竟是什么问题?我该如何解决?