S
Stephan Hoffmann
Hi,
I'm new to std::auto_ptr<> and wanted to use it with
a base class and several derived classes.
I'm using gcc 3.3.5 and get a compile error I don't know
how to resolve when compiling the following (in file testInteger.cc):
line 38: std::auto_ptr<HInteger> d(new HInteger(5));
line 39: std::auto_ptr<HObject> e(new HObject());
line 40: e= d;
Here is the error
/usr/include/c++/3.3.5/memory: In member function `std::auto_ptr<_Tp>&
std::auto_ptr<_Tp>:perator=(std::auto_ptr<_Tp1>&) [with _Tp1 =
HInteger,
_Tp = HObject]':
testInteger.cc:40: instantiated from here
/usr/include/c++/3.3.5/memory:237: error: no matching function for call to `
std::auto_ptr<HObject>::reset(HInteger*)'
/usr/include/c++/3.3.5/memory:316: error: candidates are: void
std::auto_ptr<_Tp>::reset(_Tp*) [with _Tp = HObject]
HInteger is derived from HNumber which is derived from HObject.
As I'm not familiar with auto_ptr, I tested this with a trivial
example: a class Base and a class Derived and all of the following
compiles fine:
std::auto_ptr<Base> a(new Base());
std::auto_ptr<Derived> b(new Derived());
std::auto_ptr<Base> c(new Derived());
a= b;
Originally, my 'root' class HObject was abstract (had pure virtual members),
but removing that didn't change this error message.
So I guess one of my classes HObject, HNumber, or HInteger is missing
a member function, but I don't know what that could be. I do not
hide any of the functions that may be constructed by the compiler
(default or copy c'tor, assignment operator). The destructor is
virtual and public in all 3 classes.
Any hint appreciated, thanks,
Stephan
I'm new to std::auto_ptr<> and wanted to use it with
a base class and several derived classes.
I'm using gcc 3.3.5 and get a compile error I don't know
how to resolve when compiling the following (in file testInteger.cc):
line 38: std::auto_ptr<HInteger> d(new HInteger(5));
line 39: std::auto_ptr<HObject> e(new HObject());
line 40: e= d;
Here is the error
/usr/include/c++/3.3.5/memory: In member function `std::auto_ptr<_Tp>&
std::auto_ptr<_Tp>:perator=(std::auto_ptr<_Tp1>&) [with _Tp1 =
HInteger,
_Tp = HObject]':
testInteger.cc:40: instantiated from here
/usr/include/c++/3.3.5/memory:237: error: no matching function for call to `
std::auto_ptr<HObject>::reset(HInteger*)'
/usr/include/c++/3.3.5/memory:316: error: candidates are: void
std::auto_ptr<_Tp>::reset(_Tp*) [with _Tp = HObject]
HInteger is derived from HNumber which is derived from HObject.
As I'm not familiar with auto_ptr, I tested this with a trivial
example: a class Base and a class Derived and all of the following
compiles fine:
std::auto_ptr<Base> a(new Base());
std::auto_ptr<Derived> b(new Derived());
std::auto_ptr<Base> c(new Derived());
a= b;
Originally, my 'root' class HObject was abstract (had pure virtual members),
but removing that didn't change this error message.
So I guess one of my classes HObject, HNumber, or HInteger is missing
a member function, but I don't know what that could be. I do not
hide any of the functions that may be constructed by the compiler
(default or copy c'tor, assignment operator). The destructor is
virtual and public in all 3 classes.
Any hint appreciated, thanks,
Stephan