forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C++ Noob needs help with classes

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Luke



Joined: 21 Sep 2006
Posts: 5

PostPosted: Thu Sep 21, 2006 11:37 pm    Post subject: C++ Noob needs help with classes Reply with quote

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
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Fri Sep 22, 2006 12:30 am    Post subject: Reply with quote

Building your source as C++ instead of plain C would probably help a lot. (Hint: .cpp instead of .c)
_________________
GE Dominator
Back to top
View user's profile Send private message
Luke



Joined: 21 Sep 2006
Posts: 5

PostPosted: Fri Sep 22, 2006 12:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Fri Sep 22, 2006 1:43 am    Post subject: Reply with quote

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/mixing-c-and-cpp.html#faq-32.3

PS have you included all the neccesary libraries in the makefile?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Luke



Joined: 21 Sep 2006
Posts: 5

PostPosted: Fri Sep 22, 2006 3:19 am    Post subject: Reply with quote

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
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Fri Sep 22, 2006 5:07 am    Post subject: Reply with quote

#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
View user's profile Send private message
danzel



Joined: 04 Nov 2005
Posts: 182

PostPosted: Fri Sep 22, 2006 5:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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