S S schrieb:
I have a little question.
Usually we assign
String str = "hello";
char* p = str.Str(); //here Str() returns a char*, not a copy
or we do
char* p = strdup(str.Str()) // incase if scope of str is local, here we
do copy
But some of the times I have seen implementation like
char* p = str; //here I suppose p will get String& ,
char* is always a pointer to char, never a reference to some class. If
you had actually &str in mind, I would doubt that -- pointers are
strongly typed in C++ (if you do not lie to the compiler via some
do_not_use_cast<>);
does it implicitly converts it into char*? Is there some overloading
function in String class which I do not see any. Can someone tell.
I don't know about a class 'String' (well, actually I have seen a
few...). I know about 'string', which is Standard C++.
You maybe want to look up in the header file for class String, there you
can see if String supports implicit casts to some types, or not.
std::string definitly does not, and for a reason. Implicit casts on
string types most times do more harm than good, and sometimes they are
just done plain wrong (best example of how not to do it: Microsoft's
_bstr_t).
Please note that non-standard c++ libraries are usually Off-Topic here.
Best regards,
-- Markus
Thanks
-SS