473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error with boost::shared_ptr<T> with incomplete T, VC7.1 ?

I just ported old (VC6) working code to VC7.1 and have trouble with
something like:

class A; // forward
typedef boost::smart_ptr<A> Aptr;
class B{
Aptr a;
virtual ~B(); // implemented after A has been defined
};

I get an "use of undefined type 'A'' in checked_delete.hpp at
template<class T> inline void checked_delete(T * x)

{

typedef char type_must_be_complete[sizeof(T)];

delete x;

}

what's wrong ? thanks!
--
Philippe Guglielmetti - www.dynabits.com
Jul 19 '05 #1
4 3116
"Philippe Guglielmetti" <ne**@dynabits.com> wrote in message
news:3f**********************@news.sunrise.ch...
I just ported old (VC6) working code to VC7.1 and have
trouble with something like:
[...]


The best place to ask these questions is on the Boost user
list. Or, if you prefer a news interface, try GMANE
(news.gmane.org).

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
Jul 19 '05 #2
On Thu, 9 Oct 2003 09:53:43 +0200, "Philippe Guglielmetti"
<ne**@dynabits.com> wrote:
I just ported old (VC6) working code to VC7.1 and have trouble with
something like:

class A; // forward
typedef boost::smart_ptr<A> Aptr;
shared_ptr?
class B{
Aptr a;
virtual ~B(); // implemented after A has been defined
The destructor doesn't matter, since shared_ptr uses a trick that only
requires the held type to be complete where you construct the pointer.
};

I get an "use of undefined type 'A'' in checked_delete.hpp at
template<class T> inline void checked_delete(T * x)

{

typedef char type_must_be_complete[sizeof(T)];

delete x;

}

what's wrong ? thanks!


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.

Tom
Jul 19 '05 #3
"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" ? 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.
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 ?

--
Philippe Guglielmetti - www.dynabits.com
"tom_usenet" <wrote:
I just ported old (VC6) working code to VC7.1 and have trouble with
something like:

class A; // forward
typedef boost::smart_ptr<A> Aptr;


shared_ptr?
class B{
Aptr a;
virtual ~B(); // implemented after A has been defined


The destructor doesn't matter, since shared_ptr uses a trick that only
requires the held type to be complete where you construct the pointer.
};

I get an "use of undefined type 'A'' in checked_delete.hpp at
template<class T> inline void checked_delete(T * x)

{

typedef char type_must_be_complete[sizeof(T)];

delete x;

}

what's wrong ? thanks!


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.

Tom

Jul 19 '05 #4
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
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: pub | last post by:
When creating a list: list<class A*> l; How to delete all the objects whose pointers are contained in "l"? Thanks for your comments?
2
by: Dennis Jones | last post by:
Hello, Given something like: boost::shared_ptr<T> t( new T() ); What is the best (correct?) way to dereference the pointer? The following two methods work. Is there a difference?
3
by: Evgeny | last post by:
Hi, all! I didn't find yet solution for this problem! Somebody knows where is a catch? Looks like "operator =" or copy constructor not implemented in one of internal templates.... Thanks in...
24
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET...
5
by: google | last post by:
Hi All, I'm just getting started learning to use <algorithm> instead of loads of little for loops, and I'm looking for a bit of advice/mentoring re: implementing the following... I have a...
1
by: Colin Caughie | last post by:
Is there a general rule/convention for when to use angle brackets and when to use quotes in #include statements? Is the angle bracket reserved for "system" header files (e.g. standard library...
6
by: Martin | last post by:
Hi I need to maintain a <setof pointers to objects, and it must be sorted based on the values of pointed objects, not pointer values. I can achieve this easily by defining my own comparing...
3
by: Emmanuel Deloget | last post by:
Hello y'all, I'm currently writing a serie of blog tickets about the TR1, both from a definition point of view and from an implementation point of view. The next iteration in the series deals...
6
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I have a class hierarchy distributed over 3 native C++ dlls. The base class has a .NET Windows.Form for status output via a gcroot<>. The gcroot is declared private - the sub classes only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.