P
PengYu.UT
I have the following program. The auto_ptr cause the compile error.
When I change auto_ptr to pointer, the error gone.
Would you please help me to understand what is wrong?
/*******************************************/
class iterator {
private:
std::auto_ptr<int> _iterator;
// int *_iterator;
};
class collection {
public:
iterator begin() {
return iterator();
}
};
int main() {
collection va;
iterator it(va.begin());
}
/***********************************/
The error message:
main_test.cc: In member function `iterator collection::begin()':
main_test.cc:49: error: no matching function for call to
`iterator::iterator(iterator)'
main_test.cc:40: note: candidates are: iterator::iterator(iterator&)
main_test.cc: In function `int main()':
main_test.cc:56: error: no matching function for call to
`iterator::iterator(iterator)'
main_test.cc:49: note: candidates are: iterator::iterator()
main_test.cc:40: note: iterator::iterator(iterator&)
When I change auto_ptr to pointer, the error gone.
Would you please help me to understand what is wrong?
/*******************************************/
class iterator {
private:
std::auto_ptr<int> _iterator;
// int *_iterator;
};
class collection {
public:
iterator begin() {
return iterator();
}
};
int main() {
collection va;
iterator it(va.begin());
}
/***********************************/
The error message:
main_test.cc: In member function `iterator collection::begin()':
main_test.cc:49: error: no matching function for call to
`iterator::iterator(iterator)'
main_test.cc:40: note: candidates are: iterator::iterator(iterator&)
main_test.cc: In function `int main()':
main_test.cc:56: error: no matching function for call to
`iterator::iterator(iterator)'
main_test.cc:49: note: candidates are: iterator::iterator()
main_test.cc:40: note: iterator::iterator(iterator&)