c++ - 错误 : type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'

标签 c++ qt qlist

我正在尝试拥有一个 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 中使用这个 Right

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 文档,它指定要使用的对象是可分配类型,并且我已经实现了所需的功能。

提前感谢您的帮助:)

最佳答案

这意味着您正确在其他地方定义为变量、枚举常量或类似的。例如,这是一个重现您的问题的测试用例:

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

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

QList<class Right> getRights();

尽管使用 IDE 或 something else 追踪 Right 的其他定义会更好并解决问题的根源。

关于c++ - 错误 : type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33421058/

相关文章:

c++ - 添加要由#includes 使用的文件

c++ - 错误:没有用于调用 BSTLink::construct(BST*, BST*, BST*) 的匹配函数

使用 QList 时 Qt 崩溃(堆损坏)

c++ - 在函数内部初始化 unsigned char 指针返回空指针

qt - 将 AVFrame 转换为 RGB32 时在 sws_scale 处崩溃

c++ - 无法使用初始化列表初始化 QQueue

c++ - Qt:使用另一个参数创建一个新类

c++ - ctrl+alt+del 禁止在window操作系统中使用c

c++ - 如果我在 DFS 方法中生成频繁模式,如何构建 DFS 树?

qt - QtWebEngine 依赖应用程序的静态构建