ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
i m sorry but i forgot to tell about the error message..
in the function defination
u see that i have declared
const char* x;
if i deleted the const word ,the error will appear..
invalid conversion from const char* to char*
Since you're using C++ I strongly recommend std::string instead of char* or const char*. You can always pass an std::string.c_str() to library functions which need const char* arguments and it's much less hassle to use std::string in all your programs since you needn't allocate and deallocate memory each time like you do for char*.
edit: since you're already using namespace std, it should be a matter of just declaring it as
string a_str = "A string";
Last edited by vharishankar; 08-04-2006 at 06:42 AM.
You declared current as const char* so you have to declare x also as const, because there is no impicite conversion from const char* to char* (exactly what the error message told you). If you necessarily need to assign a "const" to a "non-const", then you can use the explicite convert operator const_cast:
const char *current;
x = const_cast<char*>(current);
But be careful; very often you should consider to change your design instead of using const_cast. You may also want to go through some tutorials about type casting as well as the const modfier in C++. Simply ask google for these words.
PS. And as Harishankar said already: You should consider to use std::string
Const correctness is a good thing. You are making a promise that you are not going to modify the stuff something points to, etc. So either you keep the promise, or you don't make it in the first place. What's so hard about that?
but call: meta_data::decode_int( const char* current ,int* charecter_lenght , long* integer )
and get: invalid conversion from `const char*' to `char*'
and for me it should be: invalid conversion from `char*' to `const char*'
It should not be a proble with const char to char but a problem with char to const char.
No, you can always do that. Do you understand what the const means? "const char *" means you cannot do anything that can modify the things pointed to by the pointer, which is more restrictive than "char *", so it's always okay to convert from "char *" to "const char *", but not the other way.