其他分享
首页 > 其他分享> > c-错误:“模板类QList”的模板参数列表中参数1的类型/值不匹配

c-错误:“模板类QList”的模板参数列表中参数1的类型/值不匹配

作者:互联网

我试图拥有一个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或something else来查找Right的其他定义并解决问题的根源.

标签:qlist,c,qt
来源: https://codeday.me/bug/20191013/1908172.html