LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2006, 06:20 PM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
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.
 
Old 03-12-2006, 06:29 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
invalid conversion from `const char*' to `char'
:
You need to cut/paste at least one of lines 21, 27, 33 and/or 48. Along with the declaration of the char[] variable in question.

Quote:
x/y undeclared
:
It sounds like you're missing an "int x, y;" in your move_XXX function(s).

Here's one example of "char[]" usage that could cause such a message:

Code:
char * foo (const char * s);
...
  char mystring[] = "hello world";
  foo (s[0]);
 
Old 03-12-2006, 06:37 PM   #3
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
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.
 
Old 03-12-2006, 06:44 PM   #4
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
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$
 
Old 03-12-2006, 07:43 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

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);
IMHO
 
Old 03-12-2006, 10:35 PM   #6
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from char[100] to char* ? zahadumy Programming 2 12-11-2005 09:04 PM
Help with Conversion from Sting to Char Diederick Programming 2 11-30-2005 08:00 AM
C programming int to char conversion paranoid times Programming 15 03-17-2005 11:06 PM
c++ ERROR: int to const char ashirazi Programming 6 08-06-2004 10:01 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration