Raphael Cal
Raphael Cal

Reputation: 1

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;" 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

#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

Upvotes: 0

Views: 194

Answers (1)

Paul Floyd
Paul Floyd

Reputation: 6946

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.

Upvotes: 1

Related Questions