This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: auto_ptr conversion confusion
- From: John Love-Jensen <eljay at adobe dot com>
- To: Kristian Spangsege <kks at framfab dot dk>, <gcc-help at gcc dot gnu dot org>
- Date: Fri, 11 Oct 2002 14:59:14 -0500
- Subject: Re: auto_ptr conversion confusion
Hi Kristian,
Even though a "B" is an "A". (Structs inherit their superclasses as public
by default.) This "auto_ptr<B>" is not one an "auto_ptr<A>".
Fix your code like this:
1 #include <memory>
2 using namespace std;
3
4 struct A {};
5 struct B: A {};
6
7 auto_ptr<A> f()
8 {
9 auto_ptr<A> b(new B);
10 return b;
11 }
12
13 int main()
14 {
15 auto_ptr<A> a = f();
16 return 0;
17 }
And it should work, at least with GCC 3.2.
--Eljay