Why can't push a "const auto_ptr" into a "vector"

Discussion in 'C++' started by bucher, Oct 22, 2003.

  1. bucher

    bucher Guest

    Hi,
    I want to push a const auto_ptr into a vector, but the compile reports
    errors.
    Below is the code.
    class Folder;
    class Result;
    class Results
    {
    public:
    int size(){return _Items.size();}
    const vector<const auto_ptr<Result> >& Items()const{return _Items;}
    Results();
    ~Results();
    private:
    vector<const auto_ptr<Result> > _Items;
    };

    Results::Results()
    {
    typedef list<const auto_ptr<Result> > ResultVector;
    Result* hdresult = new Result();
    auto_ptr<Result> hdptr(hdresult);
    _Items.push_back(hdptr);
    }

    The compile reports "could not find a match for operator new(unsigned
    long, auto_ptr<Result>*)" in "_construct.h".


    There is another piece of code:
    map<string, const auto_ptr<Folder> > folderMap;
    Folder* folder = new Folder(FolderName);
    auto_ptr< Folder > folder_ptr(folder);
    folderMap.insert( make_pair(FolderName, folder_ptr) );

    I think they are very similar, but the compile doesn't report errors
    about this code.

    What's wrong with my code? Thanks in advance.
     
    bucher, Oct 22, 2003
    #1
    1. Advertising

  2. bucher

    Ron Natalie Guest

    "bucher" <> wrote in message news:...
    > Hi,
    > I want to push a const auto_ptr into a vector, but the compile reports


    Standard containers require operators that are copy constructable and
    assignable. Auto_ptr does not meet these constraints.

    Further, you can't practically make a vector out of const things anyhow
    (as opposed to pointer to const things) because a const object doesn't
    meet the assignable requirement.
     
    Ron Natalie, Oct 22, 2003
    #2
    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. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,261
    Smokey Grindel
    Dec 2, 2006
  2. Rein Anders Apeland
    Replies:
    4
    Views:
    484
    Rein Anders Apeland
    Sep 15, 2005
  3. Replies:
    8
    Views:
    2,003
    Csaba
    Feb 18, 2006
  4. XyZaa
    Replies:
    0
    Views:
    603
    XyZaa
    Jul 19, 2007
  5. samppi
    Replies:
    27
    Views:
    552
    David A. Black
    Dec 5, 2007
Loading...

Share This Page