简体   繁体   English

C ++无效使用{令牌前的不完整类型或预期的初始化程序

[英]C++ Invalid use of Incomplete Type or Expected Initializer before { Token

I have seen people with this same problem but the solution doesn't work for me or maybe i am misunderstanding it. 我见过同样问题的人,但是解决方案对我不起作用,或者我误解了。 My class employee inherits from my class customer because an employee can be a customer but they have a rank, username and password. 我的班级员工继承自班级客户,因为该员工可以是客户,但他们具有等级,用户名和密码。 When i inherit it tells me invalid use of incomplete type. 当我继承时,它告诉我无效使用了不完整的类型。 But i have already tried solutions and in my derived class (employee) i #include "customer.h" or forward declare "class customer;" 但是我已经尝试过解决方案,并且在派生类(员工)中,我#include“ customer.h”或转发声明为“ class customer”; or do both in my employee.h file but it tells me this error or it says expected class name before { Really need the help 或在我的employee.h文件中同时执行这两个操作,但是它告诉我此错误,或者在{之前确实需要帮助

#ifndef CUSTOMER_H
#define CUSTOMER_H

#include "items.h"

class items;

class employee;

namespace Ui {
class customer;
}

class customer : public QMainWindow
{

    Q_OBJECT

public:
    explicit customer(QWidget *parent = 0);
    customer(int, QString, QString, QString, QDate, QString, QString, int, int, QString);

    ~customer();

    //START set and get functions
    void setID(int);
    int getID();

    void setFirstName(QString);
    QString getFirstName();

    void setLastName(QString);
    QString getLastName();

    void setGender(QString);
    QString getGender();

    void setDateOfBirth(QDate);
    QDate getDateOfBirth();

    void setStreet(QString);
    QString getStreet();

    void setTown(QString);
    QString getTown();

    void setDistrictID(int);
    int getDistrictID();

    void setContactNumber(int);
    int getContactNumber();

    void setEmail(QString);
    QString getEmail();
    //END set and get functions

    virtual void resetFields();

protected:
    Ui::customer *ui;


private slots:
    void on_pushButton_AddCustomer_clicked();

    void on_pushButton_Clear_clicked();

    void on_pushButton_ViewAllCustomers_clicked();

    void on_pushButton_AddEmployee_emp_clicked();


    void on_pushButton_Clear_emp_clicked();

    void on_buying_pushButton_clicked();

    void on_buying_pushButton_emp_clicked();

};

#endif // CUSTOMER_H


EMPLOYEE CLASS BELOW

#ifndef EMPLOYEE_H
#define EMPLOYEE_H


#include "ui_customer.h"
#include "database.h"

#include <QMainWindow>

#include "customer.h"
class customer;
class employee : public customer
{
    Q_OBJECT
public:

    employee(int, QString, QString, QString, QDate, QString, QString, int, int, QString, QString, QString, QString);

    void setRank(QString);
    QString getRank();

    void setUsername(QString);
    QString getUsername();

    void setPassword(QString);
    QString getPassword();

    virtual void resetFields();

};

#endif // EMPLOYEE_H

You can only use forward declaration of types if the compiler does not need to know anything about the size or layout of the type. 如果编译器不需要了解有关类型的大小或布局的任何信息,则只能使用类型的前向声明。 This is the case if you have a pointer or reference to your forward declared type. 如果您有一个指向前向声明类型的指针或引用,就是这种情况。 It isn't the case if you want to instantiate or inherit from the type. 如果要实例化或继承该类型,则不是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM