On Thu, 9 Oct 2003 17:58:56 +0200, "Philippe Guglielmetti"
<ne**@dynabits.com> wrote:
"tom_usenet" wrote:
shared_ptr?
yes, sure, sorry : typedef boost::shared_ptr<A> Aptr;
>class B{
>Aptr a;
>};
>
>I get an "use of undefined type 'A'' in checked_delete.hpp
A must be complete in every place to attempt to create an Aptr. If you
do that, you shouldn't be getting the error. The example you've shown
isn't enough to diagnose the problem though.
What do you mean by "create" ?
Construct, passing an A*.
The error happens when compiling the line
Aptr a, which is when I *declare* the variable a.
I know the A type should be defined when the variable is *constructed*, in
B's constructors.
Right, and that's the only place it need be complete for shared_ptr to
work.
This was the case with VC6, where shared_ptr worked just like "regular
"pointers, where I can write:
class C {
A* a;
};
and compile this even with A not defined. What has changed in VC7.1 ?
Lots, but this still works (the trick is a standard one - it doesn't
rely on language extensions). This compiles fine on my VC7.1 (boost
1.30.0):
#include <boost/shared_ptr.hpp>
class A;
typedef boost::shared_ptr<A> Aptr;
class B{
public:
Aptr a;
virtual ~B(); // implemented after A has been defined
};
class A
{
};
B::~B(){
}
int main()
{
B b;
b.a = Aptr(new A);
}
Are you sure you have the latest version of boost? Could you post a
complete program exhibiting the problem?
Tom