C++ (Qt)#ifndef MYCLASS_H#define MYCLASS_H #include <QScopedPointer> class MyClass2; class MyClass{public: MyClass(); ~MyClass(); QScopedPointer<MyClass2> _ptr; }; #endif // MYCLASS_H
C++ (Qt)#include "myclass.h"#include "myclass2.h" MyClass::MyClass(){ this->_ptr.reset(new MyClass2);} MyClass::~MyClass() { }
C++ (Qt)#ifndef MYCLASS2_H#define MYCLASS2_H #include "myclass.h" class MyClass2{public: MyClass2() { }; ~MyClass2() { };}; #endif // MYCLASS2_H
C++ (Qt)#include "myclass.h" int main(int argc, char *argv[]){ MyClass obj;}
C++ (Qt)template <typename T>struct QScopedPointerDeleter{ static inline void cleanup(T *pointer) { // Enforce a complete type. // If you get a compile error here, read the secion on forward declared // classes in the QScopedPointer documentation. typedef char IsIncompleteType[ sizeof(T) ? 1 : -1 ]; (void) sizeof(IsIncompleteType); delete pointer; }};