 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chris Hill Guest
|
Posted: Sat Apr 24, 2004 12:27 am Post subject: HP aCC auto_ptr as value parameter with default value proble |
|
|
I'm pulling my hair out here. I have some code that works on a number
of platforms and compilers (gcc 2.96 and 3.x and also Sun Workshop
C++). It makes extensive use of auto_ptr value parameters to make
explicit that ownership of objects is being passed into functions.
So, littered around the code are functions of the form:
void foo(std::auto_ptr<T> t){...}
With the callers calling them as:
// do some stuff
// create T and pass it into foo
foo(std::auto_ptr<T>(new T));
However, some of the time I want to be able to default initialise
the values passed into the function, code like:
void foo(std::auto_ptr<T> t = std::auto_ptr<T>(new T)){...}
// call foo create a DerivedFromT
foo(std::auto_ptr<T>(new T));
// call foo use the default version of t
foo();
This all works on the *Nix compilers I've come across so far but fails
to compile on HP aCC (with -AA). The error message I get, for the
following example code is:
hump [82]% /opt/aCC/bin/aCC -AA t.cxxError 226: "t.cxx", line 18
#No appropriate function found for call of
'auto_ptr::auto_ptr'. Last viable candidate was
"std::auto_ptr<char>::auto_ptr(std::auto_ptr<char> &)"
["/opt/aCC/include_std/memory",
line 833]. Argument of type 'class auto_ptr<char>' could not
be converted to 'std::auto_ptr<char> &'.
wobble();
^^^^^^^^
The sample code is:
hump [84]% cat t.cxx
#include <memory>
using namespace std;
void wobble(
auto_ptr<char> c = auto_ptr<char>(new char)
)
{
}
int main(int argc, char** argv)
{
std::auto_ptr<char> c(
std::auto_ptr<char>(new char)
);
wobble(c);
wobble();
return 0;
}
Can anyone cast any light onto what I'm doing wrong, or how
I can go about giving these auto_ptr values default values.
:) Chris.
PS. I've tried googling for an answer but not come up with anything.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|