【C++】template 統合スレ -- STL/Boost/Loki, etc.
■ このスレッドは過去ログ倉庫に格納されています
0012デフォルトの名無しさん
NGNGclass B {};
class D : public B {};
std::auto_ptr<B> f()
{
  std::auto_ptr<D> p;
  return p;
}
↑の一見通りそうだけど、エラーになります。
test.cpp:9: no matching function for call to `std::auto_ptr<B>::auto_ptr(
std::auto_ptr<B>)'
/usr/include/c++/3.1.1/memory:346: candidates are:
std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr_ref<_Tp>) [with _Tp = B]
/usr/include/c++/3.1.1/memory:216:
std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = B, _Tp = B]
/usr/include/c++/3.1.1/memory:203:
std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = B]
test.cpp:9: initializing temporary from result of `
std::auto_ptr<_Tp>::operator std::auto_ptr<_Tp1>() [with _Tp1 = B, _Tp = D]'
とりあえず、
  return std::auto_ptr<B>( p );
で、エラーにならなくなるようです。
この修正が妥当なんでしょうか?
■ このスレッドは過去ログ倉庫に格納されています