473,492 Members | 4,301 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

compile errors with list of auto_ptr

gg
I am getting the following compilation errors with the following
program. My compiler is aCC 03.27 on HP-UX11 -

#include <iostream>
using namespace std;

#include <list>
#include <memory>
#include <string>

int main ( void )
{
auto_ptr < list < auto_ptr < string > > > list1;
auto_ptr < list < auto_ptr < string > > > list2;

auto_ptr < string > strAPT1 (new string ( "a" ) );
auto_ptr < string > strAPT2 (new string ( "b" ) );
auto_ptr < string > strAPT3 (new string ( "c" ) );

list1->push_back ( strAPT1 );
list1->push_back ( strAPT2 );
list1->push_back ( strAPT3 );
}
Error 226: "/opt/aCC/include_std/memory", line 187 # No appropriate
function found for call of 'auto_ptr::auto_ptr'. Last viable
candidate was
"std::auto_ptr<std::basic_string<char,std::char_tr aits<char>,std::allocator<char>
::auto_ptr(std::basic_string<char,std::char_trait s<char>,std::allocator<char> > *)" ["/opt/aCC/include_std/memory", line 830]. Argument of type 'const
std::auto_ptr<std::basic_string<char,std::char_tra its<char>,std::allocator<char>
&' could not be converted to
'std::basic_string<char,std::char_traits<char>,std ::allocator<char> >
*'.
new (__p) _TypeT (__val);
^^^^^^^^^^^^^^^^^^^^^^^^
Error 556: "/opt/aCC/include_std/list", line 911 # Unable to generate
specialization "void

__rw::__rw_construct<std::auto_ptr<std::basic_stri ng<char,std::char_traits<char>,std::allocator<char > ,std::auto_ptr<std::basic_string<char,std::char_t raits<char>,std::allocator<char> > > (std::auto_ptr<std::basic_string<char,std::char_t raits<char>,std::allocator<char> > > *,const
std::auto_ptr<std::basic_string<char,std::char_tra its<char>,std::allocator<char> &)" due to errors during generation. _RWSTD_VALUE_ALLOC (_C_value_alloc_type,
^^^^^^^^^^^^^^^^^^
Error 556: "/opt/aCC/include_std/list", line 911 # Unable to generate
specialization "void

__rw::__rw_construct<std::auto_ptr<std::basic_stri ng<char,std::char_traits<char>,std::allocator<char > ,std::auto_ptr<std::basic_string<char,std::char_t raits<char>,std::allocator<char> > > (std::auto_ptr<std::basic_string<char,std::char_t raits<char>,std::allocator<char> > > *,const


std::auto_ptr<std::basic_string<char,std::char_tra its<char>,std::allocator<char> &)" due to errors during generation.

_RWSTD_VALUE_ALLOC (_C_value_alloc_type,
^^^^^^^^^^^^^^^^^^

Aug 10 '05 #1
5 4067
gg wrote:
I am getting the following compilation errors with the following
program. My compiler is aCC 03.27 on HP-UX11 -

#include <iostream>
using namespace std;

#include <list>
#include <memory>
#include <string>

int main ( void )
{
auto_ptr < list < auto_ptr < string > > > list1;
'std::auto_ptr' does not satisfy the requirements for objects to be
contained in standard containers ('std::list' included).

Get Boost and use 'boost::shared_ptr' for that.
[...]


V
Aug 10 '05 #2
you are trying to store a pointer to std::list in an auto_ptr where as
auto_ptr works only with pointers.

thanks
rt

Aug 11 '05 #3
auto_ptr < list < auto_ptr < string > > > list1;
auto_ptr < list < auto_ptr < string > > > list2;


You should not try to store auto_ptr objects in STL containers.
auto_ptr copy semantics are different from normal objects. Copying
mutates the source auto_ptr and sets the underlying pointer to NULL.
This algorithms on the container which depend on temporary copying of
objects can fail on auto_ptr containers. An auto_ptr copy constructor /
assignment operator prototype too is slightly different:

auto_ptr(auto_ptr&); // see no X(const X&) but X(X&)

If you have a list< auto_ptr<...> > and call insert on it with a new
auto_ptr object, it won't compile. So the above code is incorrect and
'auto_ptr's are not meant to be stored in STL containers.

Cheers,
Andy

Aug 11 '05 #4
> you are trying to store a pointer to std::list in an auto_ptr where as
auto_ptr works only with pointers.


I guess if you really ever allocate an std::list on the heap, you could
use an auto_ptr to manage its heap-life. There is not problem there.

Aug 11 '05 #5

ga***********@yahoo.com schreef:
auto_ptr < list < auto_ptr < string > > > list1;
auto_ptr < list < auto_ptr < string > > > list2;


You should not try to store auto_ptr objects in STL containers.
auto_ptr copy semantics are different from normal objects. Copying
mutates the source auto_ptr and sets the underlying pointer to NULL.
This algorithms on the container which depend on temporary copying of
objects can fail on auto_ptr containers. An auto_ptr copy constructor /
assignment operator prototype too is slightly different:

auto_ptr(auto_ptr&); // see no X(const X&) but X(X&)

If you have a list< auto_ptr<...> > and call insert on it with a new
auto_ptr object, it won't compile. So the above code is incorrect and
'auto_ptr's are not meant to be stored in STL containers.


Your explanation why it won't work is perfect, but let me point out
that it's not just insert() that prevents it. Every function in list
can break, including the default constructor! Implementations differ
slightly, so you cannot say precisely which functions will break.

Regards,
Michiel Salters

Aug 11 '05 #6

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

Similar topics

1
1598
by: Ravi Chaudhary | last post by:
Hi, We are using VS.Net 2003 and coding in VB.net. The solution has 38 projects; most of the projects in the solution reference other projects (without any circular references) and all the...
3
1404
by: Carl Youngblood | last post by:
I recognize that I may not be giving sufficient information with this, but in the interest of not bogging the list down with too much code, I'll try and post just a little information and then if...
3
1852
by: arthur-e | last post by:
A new Machine was set up by our IS department - it came with Office Pro 2003. Access97, Word97 and Excel 97 were added. I'm trying to update an Access 97database to 2003 but get weird compiling...
1
1444
by: Ray Wampler | last post by:
According to the information on the Microsoft web site, code written in VB.NET 2002 can simply be recompiled using VS.NET 2003. However, I have found that code which compiles cleanly in VS.Net...
1
2051
by: Ravi Chaudhary | last post by:
Hi, We are using VS.Net 2003 and coding in VB.net. The solution has 38 projects; most of the projects in the solution reference other projects (without any circular references) and all the...
2
2458
by: donkeyboy | last post by:
All, I've tried the jythonc compiler to try and create an applet to see how it works, but I get a number of Java compile errors that are way above my knowledge. Does anyone know what any of the...
1
2618
by: =?Utf-8?B?SG93YXJkIFBpbnNsZXk=?= | last post by:
I'm trying to convert a Web Site to the Web Application project model and I'm running into compile errors that do not seem to be covered by the guidance I found at "Converting a Web Site Project to...
8
7776
by: bradyounie | last post by:
I have a C++ COM project that was created with Visual C++ 6. I have just converted the project to Visual Studio 2005 and have been trying to build it. I get the following compile errors: warning...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6862
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
7364
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...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.