How do I hide the private implementation (implicit sharing) in Qt:
I have Employee.cpp the following in my Employee.h header:
#include <QSharedData>
#include <QString>
class EmployeeData;
class Employee: public QObject
{
Q_OBJECT
public:
Employee();
Employee(int id, QString name);
Employee(const Employee &other);
void setId(int id);
void setName(QString name);
int id();
QString name();
private:
QSharedDataPointer<EmployeeData> d;
};
class EmployeeData : public QSharedData
{
public:
EmployeeData() : id(-1) { name.clear(); }
EmployeeData(const EmployeeData &other)
: QSharedData(other), id(other.id), name(other.name) { }
~EmployeeData() { }
int id;
QString name;
};
But when I move EmployeeData to a private part, say Employee.cpp I get: error: invalid use of incomplete type ‘struct EmployeeData’
However, if I change my definition to this it works fine:
class Employee
{
public:
Employee();
Employee(int id, QString name);
..
Thus, can I use QSharedData while inheriting from QObject ?