I want to design and write a class in c++ with qt design pattern. In my original class I just have one data member which is inherited from QSharedData that is named MyClassData, and some member functions. Now my question is if MyClassData includes Pointer, how should I define this Pointer in that class?
The following codes will clear my question:
class MyClassData : public QSharedData {
public:
MyClassData();
// one of these pointers is correct ?
int * myNormalPointer;
QSharePointer<int> myQSharedPointer;
QScopedPointer<int> myQScopedPointer;
};
class MyClass {
public:
MyClass();
// and some other member functions ...
QSharedDataPointer<MyClassData> data;
}
If my question will not be closed!, I wanna ask that generally is it correct to always avoid from defining Pointers in member field of a class?
Aucun commentaire:
Enregistrer un commentaire