Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
Luke
Posts: 5 Joined: Thu Sep 21, 2006 11:35 pm
Post
by Luke » Thu Sep 21, 2006 11:37 pm
Hi
I'm more or less a Noob at C++. I read 2 or three books on C++ years ago and, If one can say this about oneself, I'm a pro at PHP, but now I'm having troubles with a simple object; Here's the code of "menuitem.c"
Code: Select all
class MainMenuItem
{
public:
Image* icon;
char label[16];
int x, y;
int textoffsetTop, textoffsetLeft;
MainMenuItem(char pLabel, Image* pIcon)
{
label = pLabel;
icon = pIcon;
}
}
which I include in main.c with #include "menuitem.c".
The compiler tells me
In file included from main.c:17:
menuitem.c:1: error: syntax error before 'MainMenuItem'
menuitem.c:2: error: syntax error before '{' token
menuitem.c:10: warning: return type defaults to 'int'
menuitem.c: In function 'MainMenuItem':
menuitem.c:11: error: incompatible types in assignment
menuitem.c:12: error: 'icon' undeclared (first use in this function)
menuitem.c:12: error: (Each undeclared identifier is reported only once
menuitem.c:12: error: for each function it appears in.)
menuitem.c: At top level:
menuitem.c:14: error: syntax error before '}' token
make: *** [main.o] Error 1
Can anyone help me out?
chp
Posts: 313 Joined: Wed Jun 23, 2004 7:16 am
Post
by chp » Fri Sep 22, 2006 12:30 am
Building your source as C++ instead of plain C would probably help a lot. (Hint: .cpp instead of .c)
GE Dominator
Luke
Posts: 5 Joined: Thu Sep 21, 2006 11:35 pm
Post
by Luke » Fri Sep 22, 2006 12:35 am
I did that. Now I get these errors:
Code: Select all
main.o: In function `main':
main.cpp:(.text+0xf0): undefined reference to `initGraphics()'
main.cpp:(.text+0xfc): undefined reference to `loadImage(char const*)'
main.cpp:(.text+0x108): undefined reference to `loadImage(char const*)'
main.cpp:(.text+0x114): undefined reference to `loadImage(char const*)'
main.cpp:(.text+0x120): undefined reference to `loadImage(char const*)'
main.cpp:(.text+0x12c): undefined reference to `loadImage(char const*)'
main.cpp:(.text+0x230): undefined reference to `clearScreen(unsigned int)'
main.cpp:(.text+0x27c): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x2d0): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x32c): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x394): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x3e8): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x3f0): undefined reference to `flipScreen()'
main.cpp:(.text+0x4a4): undefined reference to `clearScreen(unsigned int)'
main.cpp:(.text+0x4ec): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x534): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x580): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x5d8): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x630): undefined reference to `printTextScreen(int, int, char c
onst*, unsigned int)'
main.cpp:(.text+0x638): undefined reference to `flipScreen()'
collect2: ld returned 1 exit status
make: *** [pspwAMPxmb.elf] Error 1
These are basically all functions I used
Ghoti
Posts: 288 Joined: Sat Dec 31, 2005 11:06 pm
Post
by Ghoti » Fri Sep 22, 2006 1:43 am
Hi I am a noob also but maybe this link helps. I guess you are using the graphics.c library for the functions and that is still c and not c++, i don't know if it is possible to combine them i have never done that but the way to do this is this (i hope :S)
http://www.parashift.com/c++-faq-lite/m ... l#faq-32.3
PS have you included all the neccesary libraries in the makefile?
Luke
Posts: 5 Joined: Thu Sep 21, 2006 11:35 pm
Post
by Luke » Fri Sep 22, 2006 3:19 am
i don't know if it is possible to combine them
yeah, that kinda seems to be the point :/... I think I'll stick to plain C then...
Thank you
dot_blank
Posts: 498 Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil
Post
by dot_blank » Fri Sep 22, 2006 5:07 am
#include "callbacks.h"
#include "framebuffer.h"
#include "graphics.h"
....
....
class MainMenuItem
{
public:
MainMenuItem(char pLabel, Image* pIcon)
{
label = pLabel;
icon = pIcon;
};
private:
mage* icon;
char label[16];
int x, y;
int textoffsetTop, textoffsetLeft;
}; //semicolon
Last edited by
dot_blank on Sat Sep 23, 2006 9:25 am, edited 1 time in total.
10011011 00101010 11010111 10001001 10111010
danzel
Posts: 182 Joined: Fri Nov 04, 2005 11:03 pm
Post
by danzel » Fri Sep 22, 2006 5:49 am
You need a semicolon ; at the end of your class definition:
class MainMenuItem
{
public:
MainMenuItem(char pLabel, Image* pIcon)
{
label = pLabel;
icon = pIcon;
};
private:
mage* icon;
char label[16];
int x, y;
int textoffsetTop, textoffsetLeft;
};
^There
HTH. :)