kuzulis
25th August 2009, 06:48
I make as it is written here: http://techbase.kde.org/Policies/Library_Code_Policy/Shared_D-Pointer_Example
mybaseclass.h
#ifndef MYBASECLASS_H
#define MYBASECLASS_H
#include <QObject>
class MyBasePrivateClass;
class MyBaseClass : public QObject
{
Q_OBJECT
public:
MyBaseClass(QObject *parent = 0);
virtual ~MyBaseClass();
void setParam(int val);
int param() const;
protected:
MyBasePrivateClass * const d_ptr;
//MyBaseClass(MyBasePrivateClass &dd, QObject *parent);
private:
Q_DECLARE_PRIVATE(MyBaseClass)
Q_DISABLE_COPY(MyBaseClass)
};
#endif
mybaseclass.cpp
#include "mybaseclass.h"
class MyBasePrivateClass
{
Q_DECLARE_PUBLIC(MyBaseClass)
public:
MyBasePrivateClass() { m_param = 0; }
virtual ~MyBasePrivateClass() {}
int m_param;
MyBaseClass *q_ptr;
};
MyBaseClass::MyBaseClass(QObject *parent)
: QObject(parent), d_ptr(new MyBasePrivateClass)
{
// Q_D(MyBaseClass);
}
MyBaseClass::~MyBaseClass()
{
delete d_ptr;
}
void MyBaseClass::setParam(int val)
{
Q_D(MyBaseClass);
d->m_param = val;
}
int MyBaseClass::param() const
{
Q_D(const MyBaseClass);
return d->m_param;
}
in console written :
D:\projects\Private_test\src>make
g++ -c -O2 -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_CORE_LIB -D
QT_THREAD_SUPPORT -I"D:/Qt/4.1.1/include/QtCore" -I"D:/Qt/4.1.1/include" -I"D:/Qt/4.1.1/include/Acti
veQt" -I"build\moc" -I"." -I"D:/Qt/4.1.1/mkspecs/win32-g++" -o build\obj\mybaseclass.o mybaseclass.c
pp
In file included from mybaseclass.cpp:1:
mybaseclass.h:19: error: ISO C++ forbids declaration of `MyBaseClassPrivate' with no type
mybaseclass.h:19: error: `MyBaseClassPrivate' declared as an `inline' field
mybaseclass.h:19: error: expected `;' before '*' token
mybaseclass.h:19: error: expected `;' before "inline"
mybaseclass.h:19: error: ISO C++ forbids declaration of `MyBaseClassPrivate' with no type
mybaseclass.h:19: error: `MyBaseClassPrivate' declared as an `inline' field
mybaseclass.h:19: error: expected `;' before '*' token
mybaseclass.h:19: error: expected `;' before "friend"
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function `void MyBaseClass:
:setParam(int)':
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h:99: error: `QObjectPrivate* QObject::d
_func()' is private
mybaseclass.cpp:28: error: within this context
mybaseclass.cpp:28: error: cannot convert `QObjectPrivate*' to `MyBaseClassPrivate* const' in initia
lization
mybaseclass.cpp:29: error: invalid use of undefined type `struct MyBaseClassPrivate'
mybaseclass.h:19: error: forward declaration of `struct MyBaseClassPrivate'
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function `int MyBaseClass::
param() const':
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h:99: error: `const QObjectPrivate* QObj
ect::d_func() const' is private
mybaseclass.cpp:34: error: within this context
mybaseclass.cpp:34: error: cannot convert `const QObjectPrivate*' to `const MyBaseClassPrivate* cons
t' in initialization
mybaseclass.cpp:35: error: invalid use of undefined type `const struct MyBaseClassPrivate'
mybaseclass.h:19: error: forward declaration of `const struct MyBaseClassPrivate'
mingw32-make: *** [build\obj\mybaseclass.o] Error 1
Help Please :( Already 2 days tormented
PS: Attach project
mybaseclass.h
#ifndef MYBASECLASS_H
#define MYBASECLASS_H
#include <QObject>
class MyBasePrivateClass;
class MyBaseClass : public QObject
{
Q_OBJECT
public:
MyBaseClass(QObject *parent = 0);
virtual ~MyBaseClass();
void setParam(int val);
int param() const;
protected:
MyBasePrivateClass * const d_ptr;
//MyBaseClass(MyBasePrivateClass &dd, QObject *parent);
private:
Q_DECLARE_PRIVATE(MyBaseClass)
Q_DISABLE_COPY(MyBaseClass)
};
#endif
mybaseclass.cpp
#include "mybaseclass.h"
class MyBasePrivateClass
{
Q_DECLARE_PUBLIC(MyBaseClass)
public:
MyBasePrivateClass() { m_param = 0; }
virtual ~MyBasePrivateClass() {}
int m_param;
MyBaseClass *q_ptr;
};
MyBaseClass::MyBaseClass(QObject *parent)
: QObject(parent), d_ptr(new MyBasePrivateClass)
{
// Q_D(MyBaseClass);
}
MyBaseClass::~MyBaseClass()
{
delete d_ptr;
}
void MyBaseClass::setParam(int val)
{
Q_D(MyBaseClass);
d->m_param = val;
}
int MyBaseClass::param() const
{
Q_D(const MyBaseClass);
return d->m_param;
}
in console written :
D:\projects\Private_test\src>make
g++ -c -O2 -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_CORE_LIB -D
QT_THREAD_SUPPORT -I"D:/Qt/4.1.1/include/QtCore" -I"D:/Qt/4.1.1/include" -I"D:/Qt/4.1.1/include/Acti
veQt" -I"build\moc" -I"." -I"D:/Qt/4.1.1/mkspecs/win32-g++" -o build\obj\mybaseclass.o mybaseclass.c
pp
In file included from mybaseclass.cpp:1:
mybaseclass.h:19: error: ISO C++ forbids declaration of `MyBaseClassPrivate' with no type
mybaseclass.h:19: error: `MyBaseClassPrivate' declared as an `inline' field
mybaseclass.h:19: error: expected `;' before '*' token
mybaseclass.h:19: error: expected `;' before "inline"
mybaseclass.h:19: error: ISO C++ forbids declaration of `MyBaseClassPrivate' with no type
mybaseclass.h:19: error: `MyBaseClassPrivate' declared as an `inline' field
mybaseclass.h:19: error: expected `;' before '*' token
mybaseclass.h:19: error: expected `;' before "friend"
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function `void MyBaseClass:
:setParam(int)':
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h:99: error: `QObjectPrivate* QObject::d
_func()' is private
mybaseclass.cpp:28: error: within this context
mybaseclass.cpp:28: error: cannot convert `QObjectPrivate*' to `MyBaseClassPrivate* const' in initia
lization
mybaseclass.cpp:29: error: invalid use of undefined type `struct MyBaseClassPrivate'
mybaseclass.h:19: error: forward declaration of `struct MyBaseClassPrivate'
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function `int MyBaseClass::
param() const':
D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h:99: error: `const QObjectPrivate* QObj
ect::d_func() const' is private
mybaseclass.cpp:34: error: within this context
mybaseclass.cpp:34: error: cannot convert `const QObjectPrivate*' to `const MyBaseClassPrivate* cons
t' in initialization
mybaseclass.cpp:35: error: invalid use of undefined type `const struct MyBaseClassPrivate'
mybaseclass.h:19: error: forward declaration of `const struct MyBaseClassPrivate'
mingw32-make: *** [build\obj\mybaseclass.o] Error 1
Help Please :( Already 2 days tormented
PS: Attach project