V
verec
Consider a first version:
--- drawable.hpp ---
#include "gcdata.hpp"
struct drawable {
...
virtual int internal_new_GC(gcdata * gcd) = 0 ;
} ;
--- gcdata.hpp ---
#include "device.hpp"
struc gcdata {
...
device * d ;
} ;
--- device.hpp ---
#include "drawable.hpp"
struct device : public drawable {
...
}
Obviously, this doesn't compile, because the "include stack",
at the point where ``struct device : public drawable'' is
reached, looks like
...drawable.hpp
.... gcdata.hpp [drawable.hpp line 2]
..... device.hpp [gcdata.hpp] line 2]
which means that. at the point where the ``struct device'' is
reached [device.hpp line 3], the struct drawable has not been
defined yet.
The fix is to rewrite gcdata with a forward declaration:
--- gcdata.hpp ---
// do NOT #include "device.hpp"
struct device ;
struc gcdata {
...
device * d ;
} ;
So far, so good.
Now, I'm not using direct pointers, but "smart" pointers
--- drawable.hpp ---
#include "gcdata.hpp"
struct drawable {
...
virtual int internal_new_GC(GCData gcd) = 0 ;
} ;
typedef envelope<drawable> Drawable ;
--- gcdata.hpp ---
#include "device.hpp"
struc gcdata {
...
Device d ;
} ;
typedef envelope<gcdata> GCData ;
--- device.hpp ---
#include "drawable.hpp"
struct device : public drawable {
...
}
typedef envelope<device> Device ;
And now I'm stuck, because the envelope template (which
is extremely close to boost::shared_ptr/bost_instrusive_ptr)
has this requirement that T must be a complete type, not a forward
declaration.
Hence, the "fix"
--- gcdata.hpp ---
// do NOT #include "device.hpp"
struct device ;
typedef envelope<device> Device ;
struc gcdata {
...
Device d ;
} ;
does NOT compile ...
Apart from tinkering with envelope<T> so that it doesn't
require a complete type (which may or may not be possible),
anyone sees a way out of this conundrum?
[BTW: this is a port of Java code: I can change the design
in only very minor ways, so the requirement that device
inherits from drawable that uses gcdata that needs device
has to stay]
Many Thanks
--- drawable.hpp ---
#include "gcdata.hpp"
struct drawable {
...
virtual int internal_new_GC(gcdata * gcd) = 0 ;
} ;
--- gcdata.hpp ---
#include "device.hpp"
struc gcdata {
...
device * d ;
} ;
--- device.hpp ---
#include "drawable.hpp"
struct device : public drawable {
...
}
Obviously, this doesn't compile, because the "include stack",
at the point where ``struct device : public drawable'' is
reached, looks like
...drawable.hpp
.... gcdata.hpp [drawable.hpp line 2]
..... device.hpp [gcdata.hpp] line 2]
which means that. at the point where the ``struct device'' is
reached [device.hpp line 3], the struct drawable has not been
defined yet.
The fix is to rewrite gcdata with a forward declaration:
--- gcdata.hpp ---
// do NOT #include "device.hpp"
struct device ;
struc gcdata {
...
device * d ;
} ;
So far, so good.
Now, I'm not using direct pointers, but "smart" pointers
--- drawable.hpp ---
#include "gcdata.hpp"
struct drawable {
...
virtual int internal_new_GC(GCData gcd) = 0 ;
} ;
typedef envelope<drawable> Drawable ;
--- gcdata.hpp ---
#include "device.hpp"
struc gcdata {
...
Device d ;
} ;
typedef envelope<gcdata> GCData ;
--- device.hpp ---
#include "drawable.hpp"
struct device : public drawable {
...
}
typedef envelope<device> Device ;
And now I'm stuck, because the envelope template (which
is extremely close to boost::shared_ptr/bost_instrusive_ptr)
has this requirement that T must be a complete type, not a forward
declaration.
Hence, the "fix"
--- gcdata.hpp ---
// do NOT #include "device.hpp"
struct device ;
typedef envelope<device> Device ;
struc gcdata {
...
Device d ;
} ;
does NOT compile ...
Apart from tinkering with envelope<T> so that it doesn't
require a complete type (which may or may not be possible),
anyone sees a way out of this conundrum?
[BTW: this is a port of Java code: I can change the design
in only very minor ways, so the requirement that device
inherits from drawable that uses gcdata that needs device
has to stay]
Many Thanks