compile error about auto_ptr

Discussion in 'C Programming' started by George2, Feb 23, 2008.

  1. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    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
    George2, Feb 23, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    auto_ptr<Derived> to auto_ptr<Base>

    Siemel Naran, Jan 10, 2005, in forum: C++
    Replies:
    2
    Views:
    1,552
    Dave Rahardja
    Jan 11, 2005
  2. gg
    Replies:
    5
    Views:
    455
    msalters
    Aug 11, 2005
  3. George2

    auto_ptr compile error

    George2, Mar 21, 2008, in forum: C Programming
    Replies:
    0
    Views:
    313
    George2
    Mar 21, 2008
  4. George2

    auto_ptr assignment compile error

    George2, Mar 30, 2008, in forum: C Programming
    Replies:
    0
    Views:
    440
    George2
    Mar 30, 2008
  5. Sousuke
    Replies:
    9
    Views:
    1,144
    Bart van Ingen Schenau
    Mar 16, 2010
Loading...

Share This Page