compile error about auto_ptr

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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;
}
[/Code]

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
.



Relevant Pages

  • Re: strange compiler message
    ... >> int main ... strcpy(blah, " blah blah "); ... When I use the wrong signature the compiler issues the following error: ... All of this because C++ introduces the concept of calling a constructor ...
    (comp.lang.cpp)
  • Re: Working with strings in c++
    ... int i; ... The use of a copy constructor to initialise myStr from the temporary ... compiler to do it the two-step way, or the compiler is allowed to refuse to ... explicit MyString(const char* arg) ...
    (microsoft.public.vc.language)
  • Re: Requesting sample code!
    ... int m_i1, m_i2; ... then a constructor is not made automatically by the compiler. ...
    (microsoft.public.vc.language)
  • Re: question on template
    ... >>int main ... Define a default constructor for Index. ... explicit Index:idx ... class iPerf: public Index ...
    (comp.lang.cpp)
  • Re: Effeciency
    ... As lame as his class is, the compiler ... > distinguish between my class and an int. ... the presence of the constructor from unsinged int means ... check with an actual integral type (via a typedef) for your release mode ...
    (comp.lang.cpp)