【发布时间】:2013-08-21 14:16:15
【问题描述】:
我尝试使用模板来定义一些类,如下所示:
.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
真正的问题是什么?我该如何解决?
【问题讨论】: