I have a header file:
class A
{
public:
DeviceProxyPtr GetDeviceProxy();
};
DeviceProxyPtr is defined in a different header file like this:
typedef SmartPtrC<DeviceProxyC> DeviceProxyPtr;
I don’t want to include DeviceProxyPtr definition header.
If a return type was DeviceProxy* I could simply use predeclaration class DeviceProxy.
Is there any way to do the same with my smart pointer class?
The fact that it’s a concrete return type makes no difference. You can forward-declare return types.
However, in this case, it’s not a class, but a typedef. You couldn’t use
class DeviceProxy, even if it was a pointer.Mind you, all hope is not lost. The point of forward declarations is to avoid dragging in too much code and slowing down the compiler. The standard iostream library has exactly the same problem. For instance,
istreamisn’t actually a class, but a typedef of abasic_istreaminstantiation. The standard library solves this by providing an<iosfwd>header that forward-declares thebasic_istreamclass template and then uses it to declare theistreamtypedef. Thus, classes that interact with theiostreamneed only#include <iosfwd>in the header file, and then#include <iostream>in the implementation file.