Hi,

I am trying to implement the D-pointer pattern for some of my classes. I've followed the tutorials http://zchydem.enume.net/2010/01/19/...nd-d-pointers/ and http://techbase.kde.org/Policies/Lib...ointer_Example but whenever I access a private member of my d-pointer, a compiler error results stating that the member is private in the given context. Q_DECLARE_PRIVATE is supposed to make my XYZPrivate class a friend of my XYZ class, so why is there a problem accessing its private data members?

Here's the relevant code:

Employer.h:
Qt Code:
  1. class EmployerPrivate;
  2.  
  3. class Employer : public Loggable
  4. {
  5. public:
  6. Employer(QString name, QString market);
  7. ~Employer();
  8.  
  9. QList<Position> findJobs() const;
  10. QString toString() const;
  11. bool hire(Person& newHire, Position pos);
  12.  
  13. protected:
  14. const QScopedPointer<EmployerPrivate> d_ptr;
  15.  
  16. private:
  17. Q_DECLARE_PRIVATE(Employer)
  18. };
To copy to clipboard, switch view to plain text mode 

Employer.cpp:
Qt Code:
  1. Employer::Employer(QString name, QString market) :
  2. d_ptr(new EmployerPrivate(name, market))
  3. {
  4. }
  5.  
  6. Employer::~Employer()
  7. {
  8. }
  9.  
  10. QList<Position> Employer::findJobs() const
  11. {
  12. Q_D(const Employer);
  13. return d->m_positions; // Compiler error: m_positions private within context
  14. }
  15.  
  16. QString Employer::toString() const
  17. {
  18. Q_D(const Employer);
  19. return QString("***Employer information***\nName: %1\nMarket: %2").arg(d->m_name).arg(d->m_market); // Compiler error
  20. }
To copy to clipboard, switch view to plain text mode 

EmployerPrivate.h:
Qt Code:
  1. class EmployerPrivate
  2. {
  3. public:
  4. EmployerPrivate(QString name, QString market);
  5.  
  6. private:
  7. QList<Position> m_positions;
  8. QString m_name;
  9. QString m_market;
  10. };
To copy to clipboard, switch view to plain text mode 

EmployerPrivate.cpp:
Qt Code:
  1. EmployerPrivate::EmployerPrivate(QString name, QString market) :
  2. m_name(name),
  3. m_market(market)
  4. {
  5. }
To copy to clipboard, switch view to plain text mode 

I've tried making both classes derive from QObject and added the Q_OBJECT macro just in case (even though, from my understanding, these aren't needed), but that also did not work.