std::auto_ptr

Kick Damien-DKICK1 DKICK1@motorola.com
Thu Jun 5 00:44:00 GMT 2003


Maybe I just utterly confused but shouldn't this work?

[kick@csdndev08 ~/tmp]% cat f00f.cc 
#include <memory>

struct Base {
    int id_;
    explicit Base(int id) : id_(id) { }
    virtual ~Base() { }
};

struct Derived : public Base {
    explicit Derived(int id) : Base(id) { }
};

void f(std::auto_ptr<Base> sink)
{ }

int main()
{
    std::auto_ptr<Derived> source(new Derived(13));
    ::f(source);
}
[kick@csdndev08 ~/tmp]% make -f/dev/null f00f
g++     f00f.cc   -o f00f
f00f.cc: In function `int main()':
f00f.cc:19: no matching function for call to `std::auto_ptr<Base>::auto_ptr(
   std::auto_ptr<Base>)'
/usr/test/awo/user_work/kick/sparc-sun-solaris2.7-32/gcc-3.2.2/include/c++/3.2.2/memory:346: candidates
   are: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr_ref<_Tp>) [with _Tp = Base]
/usr/test/awo/user_work/kick/sparc-sun-solaris2.7-32/gcc-3.2.2/include/c++/3.2.2/memory:216: 
                  std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 
   = Base, _Tp = Base]
/usr/test/awo/user_work/kick/sparc-sun-solaris2.7-32/gcc-3.2.2/include/c++/3.2.2/memory:203: 
                  std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = 
   Base]
f00f.cc:19:   initializing temporary from result of `
   std::auto_ptr<_Tp>::operator std::auto_ptr<_Tp1>() [with _Tp1 = Base, _Tp = 
   Derived]'
make: *** [f00f] Error 1
[kick@csdndev08 ~/tmp]% g++ --version
g++ (GCC) 3.2.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[kick@csdndev08 ~/tmp]% 

Should I try this with 3.2.3?  I didn't see any mention of auto_ptr in the release notes for 3.2.3, though.



More information about the Gcc mailing list