|
-
Aug 10th, 2002, 04:40 PM
#1
Thread Starter
Ya ya Baby!!!Me is Back
Cast aways const
Problem :
PHP Code:
void Menu::DrawMenu(string sCaption)
{
char * cTempo = sCaption.c_str();
// int, int, char*, WORD
VideoXY(x,0, cTempo ,YELLOW | BLIGHTBLUE);
}//End DrawMenu
I want to put the string (sCaption )to replace the char*(cTempo)
BUT I got that message :
Code:
error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
Conversion loses qualifiers
How can I transform the string to char* ???
-
Aug 10th, 2002, 05:44 PM
#2
Thread Starter
Ya ya Baby!!!Me is Back
Here is what I have thought but it doesn't work.
to but a String to a char*
myString.c_str()
But I have that error now : Cannot convert parameter 3 from 'const char *' to 'char *' Conversion loses qualifiers
Anyone can help me?
-
Aug 10th, 2002, 09:02 PM
#3
PowerPoster
Try something like this:
PHP Code:
char * cTempo = (char8)sCaption.c_str();
-
Aug 11th, 2002, 05:57 AM
#4
Monday Morning Lunatic
No need, the function should accept a const char*:
Code:
void Menu::DrawMenu(string sCaption) {
// int, int, char*, WORD
VideoXY(x, 0, sCaption.c_str(), YELLOW | BLIGHTBLUE);
}//End DrawMenu
Actually, I would suggest using const string &sCaption for performance (saves copying the string when you pass it in, and it lets the compiler inline better in some situations).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 11th, 2002, 08:36 AM
#5
Thread Starter
Ya ya Baby!!!Me is Back
VideoXY(x, 0, sCaption.c_str(), YELLOW | BLIGHTBLUE);
doesnt work! I have a constant problem
-
Aug 11th, 2002, 08:39 AM
#6
Monday Morning Lunatic
Where is the VideoXY function declared? Is it one of yours? If so, add the 'const' to the prototype if it doesn't change the source string.
You should *always* put const on something if it doesn't need to change it, to allow it to be used in a greater number of circumstances.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 11th, 2002, 08:41 AM
#7
Thread Starter
Ya ya Baby!!!Me is Back
-
Aug 11th, 2002, 08:44 AM
#8
Monday Morning Lunatic
Where does the initial function come from? Did you write it or is it API?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 11th, 2002, 09:35 AM
#9
Thread Starter
Ya ya Baby!!!Me is Back
I write it but you neeed the LPSTR at the end for the API that call SetPosXYandColor.
DrawMenu use : VIDEOXY who use : SetPosXYandColor who use API
*APi need LPSTR
Daok
-
Aug 12th, 2002, 03:31 PM
#10
Monday Morning Lunatic
Which API function are you using?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 13th, 2002, 02:27 AM
#11
Thread Starter
Ya ya Baby!!!Me is Back
Originally posted by abdul
Try something like this:
PHP Code:
char * cTempo = (char8)sCaption.c_str();
well now it work with something like that :
PHP Code:
void Menu::DrawMenu(string sCaption) {
// int, int, char*, WORD
VideoXY(x, 0,(char*) (sCaption.c_str()), YELLOW | BLIGHTBLUE);
}//End DrawMenu
-
Aug 13th, 2002, 02:42 AM
#12
PowerPoster
Originally posted by MasterDaok
well now it work with something like that :
PHP Code:
void Menu::DrawMenu(string sCaption) {
// int, int, char*, WORD
VideoXY(x, 0,(char*) (sCaption.c_str()), YELLOW | BLIGHTBLUE);
}//End DrawMenu
Ops, ya that "8" should really be "*".
-
Aug 13th, 2002, 10:58 AM
#13
Monday Morning Lunatic
Nooooo.....evil evil evil! Pass by reference!
Then use const_cast<>
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 13th, 2002, 12:04 PM
#14
Thread Starter
Ya ya Baby!!!Me is Back
const_cast<> will do the same thing?
-
Aug 13th, 2002, 12:09 PM
#15
Monday Morning Lunatic
For example:
Code:
void bad_code(char *str) {
char b;
while(*str++) {
b = *str;
}
}
void my_code() {
const char *c = "Hello there!";
// bad_code(c); // won't compile
bad_code(const_cast<char*>(c));
}
You can mostly get away with it because it's not trying to change it. Nasty things could happen in a ROM environment though :S
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 13th, 2002, 12:31 PM
#16
Thread Starter
Ya ya Baby!!!Me is Back
Thx it work well that way too
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|