This code fails to compile:
namespace boost
{
template<class T> class scoped_ptr;
}
namespace FooNamespace
{
class FooClass
{
boost::scoped_ptr<FooType> foo;
};
}
g++ says: error: field ‘foo’ has incomplete type
I thought it would be ok since I copied the scoped_ptr declaration over from the actual boost header file... What did I screw?
Note: The problem is not in FooType
. I tried substituting it by int
to no avail...
Thanks!
Forward declarations do not work if the size of the forward-declared type must be known. Since you're embedding an instance of boost::scoped_ptr<T>
in FooClass
, the size of that type must be known.
You could embed a pointer instead, but that probably would defeat the purpose of scoped_ptr<T>
in the first place. However, it would compile:
class FooClass
{
boost::scoped_ptr<FooType> *foo;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With