If I get invalid conversion from `const char*' to `char' what should I be lookin for?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If I get invalid conversion from `const char*' to `char' what should I be lookin for?
When I 'make' my program I get this error. It works just fine when all the file are combined into one file, but it got cluttered so I divided them up. Now when I do make I get this error...
george@George:~/George Lair/030506$ make
g++ -c main.cpp
main.cpp: In function `int move_left(int, int)':
main.cpp:14: error: `x' undeclared (first use this function)
main.cpp:14: error: (Each undeclared identifier is reported only once for each
function it appears in.)
main.cpp:15: error: `y' undeclared (first use this function)
main.cpp:15: error: invalid conversion from `const char*' to `char'
main.cpp: In function `int move_right(int, int)':
main.cpp:21: error: invalid conversion from `const char*' to `char'
main.cpp: In function `int move_up(int, int)':
main.cpp:27: error: invalid conversion from `const char*' to `char'
main.cpp: In function `int move_down(int, int)':
main.cpp:33: error: invalid conversion from `const char*' to `char'
main.cpp: In function `int main(int, char**)':
main.cpp:48: error: invalid conversion from `const char*' to `char'
make: *** [main.o] Error 1
george@George:~/George Lair/030506$
I'll lose the fun if I get a direct answer, but it won't be fun when I vaguely know where to begin. I know that a * is a pointer, but what is const? What do you think I should be looking for? If my question sounds to direct, then give me something that is not as direct. Thank you in advance!
--UPDATE--
I just figured out that a const char* is a char that is unmodifiable. Meaning it cannot be to the left of the = operator. So I can have a variable EQUAL the constant char, but the constant char cannot be changed. So anyways, I'll reply back once I figure out how this effects my program.
If you want the source ask me and I'll send it up the entire contents to my FTP server.
Last edited by RHLinuxGUY; 03-12-2006 at 06:24 PM.
O I copied and pasted over an old error message, I have got the x and y error fixed. Easy. And I think I got the const char problem fixed. Here is what I did, but if there is a mistake in my so-called fix/patch let me know.
I'm going try to keep this as clutterless and easy to read so people won't go over the edge while reading...
// I could not find a const char*, but I did find this... (In my file gSDL.cpp)
void display_bmp(char *file_name, int x2, int y2)
// Notice that char *file_name is a pointer, but not a const char. At least I
// don't think so.
... So now I added it to the my headerfiles.h
int x, y;
void fightque();
int fight();
int fightstart(int, int, int);
void display_bmp(char*, int, int);
... It seems to solve my problem, except it brings up a host of new problems. But the good part is that none of them are found in main.cpp, but instead are found in main.o.
Here is my 'make' output...
george@George:~/George Lair/030506$ make
g++ -c main.cpp
g++ -c fight.cpp
g++ main.o fight.o -Wall `sdl-config --cflags --libs` -lSDL -o test2
fight.o(.bss+0x0): multiple definition of `screen'
main.o(.bss+0x0): first defined here
fight.o(.bss+0x4): multiple definition of `x'
main.o(.bss+0x4): first defined here
fight.o(.bss+0x8): multiple definition of `y'
main.o(.bss+0x8): first defined here
main.o(.text+0x2b): In function `move_left(int, int)':
: undefined reference to `display_bmp(char*, int, int)'
main.o(.text+0x5d): In function `move_right(int, int)':
: undefined reference to `display_bmp(char*, int, int)'
main.o(.text+0x8f): In function `move_up(int, int)':
: undefined reference to `display_bmp(char*, int, int)'
main.o(.text+0xc1): In function `move_down(int, int)':
: undefined reference to `display_bmp(char*, int, int)'
main.o(.text+0x12b): In function `main':
: undefined reference to `display_bmp(char*, int, int)'
collect2: ld returned 1 exit status
make: *** [test031206] Error 1
george@George:~/George Lair/030506$
--UPDATE--
I think I found the source of my problem. I did not include gSDL.cpp... I hate not finding problems before I post it on these forums. I'll have to add them in now.
Last edited by RHLinuxGUY; 03-12-2006 at 06:39 PM.
Ok heres is another update. I fixed everything except multiple definitions of x and y...
Here is my make output...
george@George:~/George Lair/030506$ make
g++ -c gSDL.cpp
g++ main.o fight.o gSDL.o -Wall `sdl-config --cflags --libs` -lSDL -o test031206fight.o(.bss+0x0): multiple definition of `screen'
main.o(.bss+0x0): first defined here
fight.o(.bss+0x4): multiple definition of `x'
main.o(.bss+0x4): first defined here
fight.o(.bss+0x8): multiple definition of `y'
main.o(.bss+0x8): first defined here
gSDL.o(.bss+0x0): multiple definition of `screen'
main.o(.bss+0x0): first defined here
gSDL.o(.bss+0x4): multiple definition of `x'
main.o(.bss+0x4): first defined here
gSDL.o(.bss+0x8): multiple definition of `y'
main.o(.bss+0x8): first defined here
collect2: ld returned 1 exit status
make: *** [test031206] Error 1
george@George:~/George Lair/030506$
Glad you're squared away with the initial problems (apparently you were updating your first post simultaneous with me responding); it sounds like you'll have no difficulty fixing the "multiply defined" error, too.
STRONG SUGGESTION: Please don't use anonymous variables in your function prototypes. If you've got a parameter, please always give it a name:
Code:
POOR:
int fightstart(int, int, int);
Code:
BETTER:
int fightstart(int x, int y, int strength_level);
Thank you very much. I do not remember who I got the anonymous habbit from, but I will not use your suggestion for now on. Once I get back from my friends house(correcting problems with their computers and software), I will give it a go on the solution you recommended me. Thank you again, I'll reply back as soon as humanly possible.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.