Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2008

Tip: Looking for answers? Try searching our database.

compile error about auto_ptr

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George3 - 23 Feb 2008 14:10 GMT
Hello everyone,

I am confused to read what the compiler says. Could anyone explain what
it means?

Code:
--------------------
 
 #include <memory>
 #include <iostream>
 #include <vector>
 #include <algorithm>
 using namespace std;
 
 int main( )
 {
     int i = 0;
    
     vector<auto_ptr<int>> vc;
     for (i = 0; i < 5; i ++) // 0 1 2 3 4
     {
         auto_ptr<int> pi (new int(i));
         vc.push_back (pi);
     }
 
     return 0;
 }
 
--------------------

1>Compiling...
1>main.cpp
1>d:\program files\microsoft visual studio 9.0\vc\include\vector(1209)
: error C2558: class 'std::auto_ptr<_Ty>' : no copy constructor
available or copy constructor is declared 'explicit'
1>        with
1>        [
1>            _Ty=int
1>        ]
1>        d:\program files\microsoft visual studio
9.0\vc\include\vector(1158) : while compiling class template member
function 'void
std::vector<_Ty>::_Insert_n(std::_Vector_const_iterator<_Ty,_Alloc>,unsigned
int,const _Ty &)'
1>        with
1>        [
1>            _Ty=std::auto_ptr<int>,
1>            _Alloc=std::allocator<std::auto_ptr<int>>
1>        ]
1>        d:\visual studio
2008\projects\test_autoptr1\test_autoptr1\main.cpp(11) : see reference
to class template instantiation 'std::vector<_Ty>' being compiled
1>        with
1>        [
1>            _Ty=std::auto_ptr<int>
1>        ]
1>d:\program files\microsoft visual studio 9.0\vc\include\vector(1233)
: error C2558: class 'std::auto_ptr<_Ty>' : no copy constructor
available or copy constructor is declared 'explicit'
1>        with
1>        [
1>            _Ty=int
1>        ]

thanks in advance,
George
SvenC - 24 Feb 2008 12:56 GMT
Hi George3,

>  vector<auto_ptr<int>> vc;

Don't use auto_ptr in any STL container. Search the web for explanations.
Here is one: http://www.devx.com/tips/Tip/13606

--
SvenC

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.