This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]