If your class directly includes an element of data of this type (and not, by the way, a pointer to this type or a reference to this type), then you should have a class declaration accessible so that the compiler knows how many bytes an instance of your object occupies . This usually means that you #include header files.
However, there are methods known as compiler firewalls that can allow you to structure classes in such a way as to give the class access to objects of the appropriate type without including them directly. One of them is pImpl idiom , in which your class implementation looks like this:
class MyClass { public: private: struct Impl; Impl* pImpl; };
Here you forward the struct Impl containing your class implementation, and then store the pointer to the Impl structure in the class. Since having a pointer in your class does not require the size of the object that it points to in order to be known, this is completely normal. Then in the .cpp file you can define an Impl struct:
struct MyClass::Impl { };
and you can implement all the member functions of the class simply by following the pImpl pointer to the actual fields. This has the disadvantage that all window access requests require a pointer, but the ability to quickly change the implementation of the class makes this useful.
Another option along the same lines is to make the class an abstract base class, and then provide a static factor function that returns an object that subclasses your base class, which actually contains the implementation. For instance:
class MyClass { public: virtual ~MyClass(); virtual void doSomething() = 0; static MyClass* New(); };
Then, in the .cpp file, you can define a specific subclass of MyClass that actually does all the work:
class ActualClass: public MyClass { public: void doSomething(); private: }
and finally, implement New to create a new instance of the implementation class:
MyClass* MyClass::New() { return new ActualClass(); }
Hope this helps!