Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why can't push a "const auto_ptr" into a "vector"

Reply
Thread Tools

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

 
 
bucher
Guest
Posts: n/a
 
      10-22-2003
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.
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      10-22-2003

"bucher" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are "Array#push" and "pop" not "push!" and "pop!"? samppi Ruby 27 12-05-2007 07:24 AM
J2ME program for Push Email, IM, Push RSS on your mobile phone! XyZaa Java 0 07-19-2007 03:00 PM
Is there a way to push data into Microsoft Excel & Word from Python ? The Night Blogger Python 4 12-21-2006 04:55 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM



Advertisments