Hi Magnus,
The problem you describe is to do with scope. Because the string sString is a local variable, like all local variables it will be created on the stack. When the method ends (i.e returns), the content of the stack is lost and consequently, any local variables declared within the method will also be lost. To make your returned object persist outside of the scope of the method it must have been declared elsewhere. Such variables could be static or public/private member variables of the class or passed to the method in the parameter list.
Regards,
Fred Preston.
| "Magnus Karlsson"
<[EMAIL PROTECTED]>
09/05/2006 13:40
|
|
More problems (same issue):
I've tried conversion with c_str() but something won't work here.
Example below gives a null-string as a result:
xsd__string Test::getData()
{
std::string sString;
sString = "Test";
return (char *) sString.cStr();
}
How come?
Best regards
Magnus
> Från: "Magnus Karlsson" <[EMAIL PROTECTED]>
> Till: "Apache AXIS C User List" <[email protected]>
> Rubrik: Re: Re: Conversion fault
> Datum: Mon, 8 May 2006 09:50:12 +0000 (GMT)
Thanks!
/Magnus
> Från: Fred Preston <[EMAIL PROTECTED]>
> Till: "Apache AXIS C User List" <[email protected]>
> Rubrik: Re: Conversion fault
> Datum: Mon, 8 May 2006 10:33:33 +0100
Hi Magnus,
xsd__string is simply a char *. To convert
from one to the other do the following:-
xsd__string pXSD_String = "Test";
std::string sString;
// Converting from xsd__string to std::string
// Because the string class has overridden the '=' operator, you can simply
assign an xsd__string to a string.
sString = pXSD_String;
// Converting from std::string to xsd__string.
// The c_str() method converts the contents of the string object to a const
char *. This can then be assigned to the xsd__string variable.
pXSD_String = (char *) sString.c_str();
Regards,
Fred Preston.
| "Magnus Karlsson"
<[EMAIL PROTECTED]>
08/05/2006 09:35
|
|
I'm using Axis C++ 1.6b for Windows (XP Professional). I'd like to know how conversion is done from std::string to axiscpp::xsd__string? I want to use ordinary string management (std::string) but when I try to cast an std::string to axiscpp::xsd__string I get "error C240: 'type cast' : cannot convert from 'std:string' to 'axiscpp::xsd_string'. Would it be better to skip xsd__strings and not use them at all?
Best regards
Magnus
