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

时间:2023-01-18 16:29:31

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

我正在尝试有一个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;
};

And then using this Right in a QList

然后在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();

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.

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

Thanks for the help in advance :)

感谢您的帮助

1 个解决方案

#1


1  

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();

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.

虽然最好使用IDE或其他东西来跟踪正确的其他定义,并解决问题的根源。

#1


1  

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();

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.

虽然最好使用IDE或其他东西来跟踪正确的其他定义,并解决问题的根源。