错误:"template< class T>"模板参数列表中参数1处的类型/值不匹配. QList类" [英] error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'

查看:382
本文介绍了错误:"template< class T>"模板参数列表中参数1处的类型/值不匹配. QList类"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建QList并在编译时出现错误! 这是我的代码:

I'm trying to have a QList and getting the error when compiling! Here's my code:

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中使用此权利

And then using this Right in a QList

class FileRightsRepo
{
public:
    FileRightsRepo(QString rightsPath);
    ~FileRightsRepo() { }
    // IRightsRepo interface
     QList<Right> getRights();

private:
    QString _rightsPath; // PATH to the file containing rights
};

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

I've implemented these classes, but when i try to compile, i get the below exception:

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

哪个是getRights()的返回类型. 我已经阅读了Qt文档,其中指出要使用的对象是可分配的类型,并且已经实现了所需的功能.

Which is the return type of getRights(). I've read Qt documentation and it specifies that the object to be used is of assignable type and i've implemented the needed functions.

非常感谢您的帮助:)

推荐答案

这意味着您已经在其他地方将Right定义为变量,枚举常量或类似名称.例如,这是一个重现您的问题的测试用例:

It means that you have Right defined somewhere else as a variable, enumeration constant or similar. For example here's a test case that reproduces your problem:

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

您可以确保按照以下方式使用该类

You can make sure that you use the class as follows

QList<class Right> getRights();

尽管最好使用IDE或其他方法来跟踪Right的其他定义,问题的根源.

although it would be better to track down the other definition of Right using an IDE or something else and fix the source of the problem.

这篇关于错误:"template&lt; class T&gt;"模板参数列表中参数1处的类型/值不匹配. QList类"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆