B
bucher
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.
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.