 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Luke
Joined: 21 Sep 2006 Posts: 5
|
Posted: Thu Sep 21, 2006 11:37 pm Post subject: C++ Noob needs help with classes |
|
|
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: | 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
| Quote: | 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? |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Fri Sep 22, 2006 12:30 am Post subject: |
|
|
Building your source as C++ instead of plain C would probably help a lot. (Hint: .cpp instead of .c) _________________ GE Dominator |
|
| Back to top |
|
 |
Luke
Joined: 21 Sep 2006 Posts: 5
|
Posted: Fri Sep 22, 2006 12:35 am Post subject: |
|
|
I did that. Now I get these errors:
| Code: | 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 |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
|
| Back to top |
|
 |
Luke
Joined: 21 Sep 2006 Posts: 5
|
Posted: Fri Sep 22, 2006 3:19 am Post subject: |
|
|
| Quote: | | 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 |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Fri Sep 22, 2006 5:07 am Post subject: |
|
|
#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 _________________ 10011011 00101010 11010111 10001001 10111010
Last edited by dot_blank on Sat Sep 23, 2006 9:25 am; edited 1 time in total |
|
| Back to top |
|
 |
danzel
Joined: 04 Nov 2005 Posts: 182
|
Posted: Fri Sep 22, 2006 5:49 am Post subject: |
|
|
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. :) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|