gpt4 book ai didi

c++ - 无法使用自定义类创建 QList

转载 作者:太空宇宙 更新时间:2023-11-04 13:32:46 25 4
gpt4 key购买 nike

我正在尝试创建自定义类对象的 QList,但出现错误:

error: C2923: 'QList' : 'Read' is not a valid template type argument for parameter 'T'

我的代码(用户 header ):

#ifndef USER_H
#define USER_H

#include <QString>
#include <QList>
#include "read.h"

class User {
protected:
int id;
QString username;
QString password;
QList<Read> readBooks;
bool accountDeleted;
bool admin;
public:
User();
User(int id, QString username, QString password,
QList<Read> readBooks, bool accountDeleted, bool admin);
~User();
const int getId();
void setId(int id);
const QString getUsername();
void setUsername(QString username);
const QString getPassword();
void setPassword(QString password);
const QList<Read> getReadBooks();
void setReadBooks(QList<Read> readBooks);
const bool isAccountDeleted();
void setAccountDeleted(bool accountDeleted);
const bool isAdmin();
void setAdmin(bool admin);
};

QDataStream &operator<<(QDataStream &out, const User &user);
QDataStream &operator>>(QDataStream &in, User &user);

#endif // USER_H

Qt 给我错误列表:

...\user.h(13) : error C2065: 'Read' : undeclared identifier
...\user.h(13) : error C2923: 'QList' : 'Read' is not a valid template type argument for parameter 'T'
...\user.h(18) : error C2065: 'Read' : undeclared identifier
...\user.h(18) : error C2923: 'QList' : 'Read' is not a valid template type argument for parameter 'T'
...\user.h(27) : error C2065: 'Read' : undeclared identifier
...\user.h(27) : error C2923: 'QList' : 'Read' is not a valid template type argument for parameter 'T'
...\user.h(28) : error C2065: 'Read' : undeclared identifier
...\user.h(28) : error C2923: 'QList' : 'Read' is not a valid template type argument for parameter 'T'

阅读标题:

#ifndef READ_H
#define READ_H

#include <QDataStream>
#include "book.h"
#include "date.h"

class Read
{
protected:
//Book book;
Date addDate;
Date readDate;
bool stillReading;
public:
Read();
~Read();
//Read(Book book, Date addDate, Date readDate, bool stillReading);
//Book getBook();
//void setBook(Book book);
Date getAddDate();
void setAddDate(Date addDate);
Date getReadDate();
void setReadDate(Date readDate);
bool isStillReading();
void setStillReading(bool stillReading);
};

QDataStream &operator<<(QDataStream &out, const Read &read);
QDataStream &operator>>(QDataStream &in, Read &read);

#endif // READ_H

这本书被评论了,因为它也给出了错误...

最佳答案

...\user.h(13) : error C2065: 'Read' : undeclared identifier

看起来 Read 在 user.h 中是未知的。也许 date.h 或 book.h 也包括 user.h? (循环引用)

使用 prototype classes可以帮助防止这种情况。

关于c++ - 无法使用自定义类创建 QList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30827624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com