I need to convert String to char*, the String class has a member function:
String::operator char const *();
I can’t get it to compile, what’s the right syntax??
String my_string = "HelloWorld;
char *my_string_ptr;
my_string_ptr = const *(my_string); // this doesnt compile…
Ran Zhang wrote:
I need to convert String to char*, the String class has a member function:
String::operator char const *();
I can’t get it to compile, what’s the right syntax??
String my_string = "HelloWorld;
char *my_string_ptr;
my_string_ptr = const *(my_string); // this doesnt compile…
\
Was that a copy and paste of your code? If so you are missing a " at
the end of HelloWorld. Also what is the copiler error?
Thanks,
Rodney
oh yeah, its missing a “;” at end of Helloworld; I had “;” in my code, just
didn’t type right in here since I didn’t copy and paste it.
the compiler error i get is “syntax error at line 119”.
line 119 is my_string_ptr = const (my_string);
col(25) is the space between ‘const’ and '’;
“Rodney Dowdall” <rdowdall@qnx.com> wrote in message
news:ctol7n$g70$1@inn.qnx.com…
Ran Zhang wrote:
I need to convert String to char*, the String class has a member
function:
String::operator char const *();
I can’t get it to compile, what’s the right syntax??
String my_string = "HelloWorld;
char *my_string_ptr;
my_string_ptr = const *(my_string); // this doesnt compile…
Was that a copy and paste of your code? If so you are missing a " at
the end of HelloWorld. Also what is the copiler error?
Thanks,
Rodney
What happens when you do:
my_string_ptr = const char *(my_string);
Thanks,
Rodney
Ran Zhang wrote:
oh yeah, its missing a “;” at end of Helloworld; I had “;” in my code, just
didn’t type right in here since I didn’t copy and paste it.
the compiler error i get is “syntax error at line 119”.
line 119 is my_string_ptr = const (my_string);
col(25) is the space between ‘const’ and '’;
“Rodney Dowdall” <> rdowdall@qnx.com> > wrote in message
news:ctol7n$g70$> 1@inn.qnx.com> …
Ran Zhang wrote:
I need to convert String to char*, the String class has a member
function:
String::operator char const *();
I can’t get it to compile, what’s the right syntax??
String my_string = "HelloWorld;
char *my_string_ptr;
my_string_ptr = const *(my_string); // this doesnt compile…
Was that a copy and paste of your code? If so you are missing a " at
the end of HelloWorld. Also what is the copiler error?
Thanks,
Rodney
Rodney Dowdall wrote:
What happens when you do:
my_string_ptr = const char *(my_string);
my_string_ptr = my_string;
is sufficient, the compiler will figure out the rest.
Cheers
Anders
still says syntax error in this line, col (25) which is the space between
‘const’ and ‘char *(my_string);’
can you try it on your machine also?
“Rodney Dowdall” <rdowdall@qnx.com> wrote in message
news:ctoo45$iba$1@inn.qnx.com…
What happens when you do:
my_string_ptr = const char *(my_string);
Thanks,
Rodney
Ran Zhang wrote:
oh yeah, its missing a “;” at end of Helloworld; I had “;” in my code,
just
didn’t type right in here since I didn’t copy and paste it.
the compiler error i get is “syntax error at line 119”.
line 119 is my_string_ptr = const (my_string);
col(25) is the space between ‘const’ and '’;
“Rodney Dowdall” <> rdowdall@qnx.com> > wrote in message
news:ctol7n$g70$> 1@inn.qnx.com> …
Ran Zhang wrote:
I need to convert String to char*, the String class has a member
function:
String::operator char const *();
I can’t get it to compile, what’s the right syntax??
String my_string = "HelloWorld;
char *my_string_ptr;
my_string_ptr = const *(my_string); // this doesnt compile…
Was that a copy and paste of your code? If so you are missing a " at
the end of HelloWorld. Also what is the copiler error?
Thanks,
Rodney
when I do my_string_ptr = my_string, compiler says " can’t assign right
expression to the element on the left, source conversion type is String &,
target conversion type is char *’.
“Anders Larsen” <al@alarsen.net> wrote in message
news:pan.2005.02.01.20.42.38.731153@alarsen.net…
Rodney Dowdall wrote:
What happens when you do:
my_string_ptr = const char *(my_string);
my_string_ptr = my_string;
is sufficient, the compiler will figure out the rest.
Cheers
Anders
“Anders Larsen” <al@alarsen.net> wrote in message
news:pan.2005.02.01.20.42.38.731153@alarsen.net…
Rodney Dowdall wrote:
What happens when you do:
my_string_ptr = const char *(my_string);
That’s really bad, const char * is a cast so it should to be put between ()
and not the mystring.
my_string_ptr = my_string;
Have my_string_ptr be of type const char *.
is sufficient, the compiler will figure out the rest.
Cheers
Anders
Ran Zhang wrote:
when I do my_string_ptr = my_string, compiler says " can’t assign right
expression to the element on the left, source conversion type is String &,
target conversion type is char *’.
Strange, our compiler settings must differ somehow…
Well then, this must work:
my_string_ptr = (const char*)my_string;
Cheers
Anders
Mario charest:
what’s the right syntax then? I tried ‘my_string_ptr = (const *char)
my_string;’ . it says ‘left expression isn’t a pointer to a constant
object’.
“Mario Charest” postmaster@127.0.0.1 wrote in message
news:ctor7q$khi$1@inn.qnx.com…
“Anders Larsen” <> al@alarsen.net> > wrote in message
news:> pan.2005.02.01.20.42.38.731153@alarsen.net> …
Rodney Dowdall wrote:
What happens when you do:
my_string_ptr = const char *(my_string);
That’s really bad, const char * is a cast so it should to be put between
()
and not the mystring.
my_string_ptr = my_string;
Have my_string_ptr be of type const char *.
is sufficient, the compiler will figure out the rest.
Cheers
Anders
“Ran Zhang” <rzhang@vamcointernational.com> wrote in message
news:ctos4s$l6q$1@inn.qnx.com…
Mario charest:
what’s the right syntax then? I tried ‘my_string_ptr = (const *char)
my_string;’ . it says ‘left expression isn’t a pointer to a constant
object’.
These work for me:
char *my_string_ptr;
const char *my_const_ptr;
my_const_ptr = my_string;
my_string_ptr = (char*)(const char*)my_string;
“Ran Zhang” <rzhang@vamcointernational.com> wrote in message
news:ctos4s$l6q$1@inn.qnx.com…
Mario charest:
what’s the right syntax then? I tried 'my_string_ptr = (const *char)
(const * char ) is not valid it should be ( const char *)
my_string;’ . it says ‘left expression isn’t a pointer to a constant
object’.
That because the left expression (my_string_ptr) is not a “const char *” you
defined it as “char *”.
The error message is pretty clear.
“Mario Charest” postmaster@127.0.0.1 wrote in message
news:ctor7q$khi$> 1@inn.qnx.com> …
“Anders Larsen” <> al@alarsen.net> > wrote in message
news:> pan.2005.02.01.20.42.38.731153@alarsen.net> …
Rodney Dowdall wrote:
What happens when you do:
my_string_ptr = const char *(my_string);
That’s really bad, const char * is a cast so it should to be put between
()
and not the mystring.
my_string_ptr = my_string;
Have my_string_ptr be of type const char *.
is sufficient, the compiler will figure out the rest.
Cheers
Anders
\