错误:'template<class T> class QList'模板参数列表中参数 1 处的类型/值不匹配

error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'

本文关键字:参数 class 不匹配 列表 类型 lt template gt 错误 QList      更新时间:2023-10-16

我正在尝试一个QList,但在编译时出错了!这是我的代码:

class Right
{
public:
    Right();
    Right(const Right& other);
    Right(RightName name, QDate validity_date);
    bool isValid() const;
    bool operator==(const Right& other)const;
    Right &operator=(const Right &other);
    QString name;
    QDate expiryDate;
};

然后在QList 中使用此权限

class FileRightsRepo
{
public:
    FileRightsRepo(QString rightsPath);
    ~FileRightsRepo() { }
    // IRightsRepo interface
     QList<Right> getRights();
private:
    QString _rightsPath; // PATH to the file containing rights
};

我已经实现了这些类,但当我尝试编译时,我得到了以下异常:

error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class QSet'
  QList<Right> getRights();

这是getRights()的返回类型。我已经阅读了Qt文档,它指定要使用的对象是可分配类型的,并且我已经实现了所需的函数。

感谢您提前提供的帮助:)

这意味着您已经在其他地方将Right定义为变量、枚举常量或类似对象。例如,这里有一个重现您问题的测试用例:

class Right;
enum { Right };
QList<Right> getRights();

你可以确保你使用类如下

QList<class Right> getRights();

尽管最好使用IDE或其他东西来追踪CCD_ 2的其他定义并修复问题的根源。