[Interest] QExplicitlySharedDataPointer Example

Michael Jackson imikejackson at gmail.com
Thu Jul 18 18:29:42 CEST 2013


I tried to compile up an example of QExplicitlySharedDataPointer based off the example from the QSharedDataPointer documentation but I am receiving compile errors that just have me stumped at the moment. I am sure I am missing something but the docs seemed to indicate that I could just substitute QExplicitlySharedDataPointer for QSharedDataPointer and have this work. This is on OS X 10.8.4 with latest production Xcode 4.5.x.

********************************************
 #include <QExplicitlySharedDataPointer>
 #include <QString>

 class EmployeeData : public QExplicitlySharedDataPointer
 {
   public:
     EmployeeData() : id(-1) { }
     EmployeeData(const EmployeeData &other)
         : QExplicitlySharedDataPointer(other), id(other.id), name(other.name) { }
     ~EmployeeData() { }

     int id;
     QString name;
 };

 class Employee
 {
   public:
     Employee() { d = new EmployeeData; }
     Employee(int id, QString name) {
         d = new EmployeeData;
         setId(id);
         setName(name);
     }
     Employee(const Employee &other)
           : d (other.d)
     {
     }
     void setId(int id) { d->id = id; }
     void setName(QString name) { d->name = name; }

     int id() const { return d->id; }
     QString name() const { return d->name; }

   private:
     QExplicitlySharedDataPointer<EmployeeData> d;
 };
********************************************
COMPILE ERRORS:

[100%] Building CXX object Tools/CMakeFiles/QtFilterTest.dir/QtFilterTest.cpp.o
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest.cpp:38:
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:42:30: error: expected class name
 class EmployeeData : public QExplicitlySharedDataPointer
                             ^
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:47:12: error: member initializer 'QExplicitlySharedDataPointer' does not name a non-static data member or base class
         : QExplicitlySharedDataPointer(other), id(other.id), name(other.name) { }
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest.cpp:38:
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:39:
In file included from /Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/QExplicitlySharedDataPointer:1:
/Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/qshareddata.h:166:59: error: no member named 'ref' in 'EmployeeData'
    inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
                                                       ~  ^
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:57:6: note: in instantiation of member function 'QExplicitlySharedDataPointer<EmployeeData>::~QExplicitlySharedDataPointer' requested here
     Employee() { d = new EmployeeData; }
     ^
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest.cpp:38:
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:39:
In file included from /Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/QExplicitlySharedDataPointer:1:
/Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/qshareddata.h:192:20: error: no member named 'ref' in 'EmployeeData'
                o->ref.ref();
                ~  ^
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:57:21: note: in instantiation of member function 'QExplicitlySharedDataPointer<EmployeeData>::operator=' requested here
     Employee() { d = new EmployeeData; }
                    ^
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest.cpp:38:
In file included from /Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:39:
In file included from /Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/QExplicitlySharedDataPointer:1:
/Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/qshareddata.h:195:30: error: no member named 'ref' in 'EmployeeData'
            if (old && !old->ref.deref())
                        ~~~  ^
/Users/Shared/Toolkits/Qt-4.8.4-Cocoa/lib/QtCore.framework/Headers/qshareddata.h:169:104: error: no member named 'ref' in 'EmployeeData'
    inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
                                                                                                    ~  ^
/Users/mjackson/Workspace/DREAM3D/Tools/QtFilterTest/QtFilter.h:64:14: note: in instantiation of member function 'QExplicitlySharedDataPointer<EmployeeData>::QExplicitlySharedDataPointer' requested here
           : d (other.d)
             ^
6 errors generated.

Any help or a pointer to a short concise example would be great. 

Thanks
Mike Jackson




More information about the Interest mailing list