gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Class Definition in C

#144816 - theguy43 - Wed Nov 07, 2007 10:19 pm

Hey Everybody,

Guess its kinda hard to cover up the fact that I'm a noob at the homebrew scene, but I have a long history of programming. Plus I've gotten a few game modification under my belt... I've been out of practice with programming for the past few years, but I still remember all the fundamentals. I've tried my hand at a few basics on the NDS, 'hello world' and moving sprites...

I'm currently developing in Visual C++ Express 2005, using the PA_lib and I've run into troubles re-structuring the game into class based structure...

Code:
source/player.h(21): error: expected '=', ',', ';', 'asm' or '__attribute__' before 'playertype'


is the error I keep getting from


Code:
class playertype
{
   private:
      vector pos , vel;
      vector dstart;
      vector dfin;
      vector scroll;
      vector dash;
       public:   
      playertype(void);
      void InitPlayer(void);
      void DashPlayer(void);
      void MovePlayer(void);
      void CheckCollisions(void);
}



it could just be that I'm missing a very simple little phrase cause of my lack of practice, but any help would be greatly appreciated...
_________________
-Theguy

#144817 - Lick - Wed Nov 07, 2007 10:24 pm

Semi-colon.

class x
{
};
_________________
http://licklick.wordpress.com

#144818 - theguy43 - Wed Nov 07, 2007 10:25 pm

oops... yea... thats in the program... just didn't highlight when I was copy-ing over to the browser
_________________
-Theguy

#144824 - Lick - Wed Nov 07, 2007 11:44 pm

You're using classes in C? That's not possible. C doesn't have classes.
_________________
http://licklick.wordpress.com

#144828 - kusma - Thu Nov 08, 2007 12:57 am

theguy43 wrote:
Code:

       public:   
      playertype(void);



You're missing a return-type for the method playertype(void).

#144830 - theguy43 - Thu Nov 08, 2007 1:36 am

looking further into it... I think you might be right on that one Lick... I wasn't a 100% sure if C supported classes... think I might switch gears and change it back into an encapsulated struct...

and Kusma, that function doesn't require a return type... its for when you declare a playertype variable.. initializes the variables..

thanks for the advice,

If I get anywhere on this project I'll be sure to post the results on the boards...
_________________
-Theguy

#144831 - Lick - Thu Nov 08, 2007 1:41 am

kusma wrote:
theguy43 wrote:
Code:

       public:   
      playertype(void);

You're missing a return-type for the method playertype(void).

kusma: It's the constructor. ;)

theguy43: why not use C++? If you don't use many of the bloated stdlibs, exceptions and whatever, the size is comparable to the binaries of a C program. Also, encapsulated structs (with structmethods)... Aren't those also C++?
_________________
http://licklick.wordpress.com

#144837 - sajiimori - Thu Nov 08, 2007 3:50 am

Without C++ features, you can forward-declare a struct in a header, and define global functions that take pointers to the opaque struct. However, this imposes efficiency limitations, particularly the need for dynamic allocation and the inability to inline the global functions.

If you want encapsulation, compile as C++. Doing it without C++ features isn't hard, but it's expensive.

#144851 - kusma - Thu Nov 08, 2007 9:29 am

oh, right, missed that it was the constructor, yeah. But yeah, as pointed out here, you need to do C++ to use classes.

#144852 - keldon - Thu Nov 08, 2007 10:17 am

Don't use a spoon when you need a spade more!

#144871 - theguy43 - Thu Nov 08, 2007 6:26 pm

ugh... I'm soo rusty with programming... last real programming language I used (aside from PHP and other web-design languages) was C... so figured I'd just hop back in...


anyways.. thanks for the help... I've switched up to C++ and things are going smoothly...

I'll be sure to post any results in the forum...

oh btw this game I'm designing is a multi-player based sidescroller... I probably be back on here before too long asking for help with the WiFi, so till then, have a good one
_________________
-Theguy

#147125 - qw3rky - Fri Dec 14, 2007 8:15 pm

Quote:
I wasn't 100% sure if C supported classes...


Wow... no offense intended but, how long has it been since you picked up a compiler?

If you're looking for some help with classes, OOP, and C++ in general, I can recommend this tutorial: http://www.cplusplus.com/doc/tutorial/. Good luck with your sidescroller, but please remember one important piece of advice: take one step at a time.
_________________
I've coded about 17 different implementations of Pong. It's the game dev's "hello, world".
DualScheme - Scheme Interpreter for DS

#147507 - elyk1212 - Fri Dec 21, 2007 9:42 pm

Quote:

Wow... no offense intended but, how long has it been since you picked up a compiler?


He probably uses other languages for programming. I wouldn't blame him. Honestly, they don't even use C++/C much in Computer Science and engineering course work anymore (except in Comp graphics or if a professor has any practical sense). I actually had to learn everything on my own (except a small blurb in a class I took way back when). I learned mainly through interest.

Seriously, all my other grad student CompSci Friends don't know the first thing about C/C++ or even most pointers/memory management concepts. It's weird really, when all these high level buzz word languages take hold,, no one is going to know how to manage memory/etc.

I know plenty of guys who cannot program without a full fledged API. Hey calls it "pampered by .NET". Proprietary languages? :( , boo. I had the luck of having to design and debug embedded hardware and being forced to use systems with no ported APIs.

I have an A.I professor that referenced a page on this affect of only learning higher level programming (compromises and benefits). I should find it. It was kind of interesting.

#147508 - sajiimori - Fri Dec 21, 2007 10:09 pm

"Computer Science" degrees aren't what they used to be. I think schools should stop calling them comp sci degrees when they just mean Java and web programming or whatever. "Software Engineering" is a fine name for such programs.

Sorry, this is getting off-topic!

#147514 - keldon - Fri Dec 21, 2007 11:02 pm

lol, well technically Computer Science is not about any particular language and is about the science side - so not teaching C++ is probably more productive to teaching 90% of the CS topics! But yes, off topic ^_^

#147518 - elyk1212 - Sat Dec 22, 2007 12:39 am

Sorry for off topic ;)

You learn loads of Math, theory and science as Keldon said. But the difference is the practical aspects (such as a industry standard language) are neglected due to being "too complex" or other such ridiculous reasons. That's why I did Computer Engineering for undergrad :)... but no Masters Science offered in CE! So now I am stuck doing MS in CS, but I still like it. More focused now.

Anyway, the point I am making is that C++ people who are not using it in industry, or are new grads, are harder to find these days. Not a surprise many folks don't remember c++ syntax etc.

Unfortunately for the non Engineers (CS majors, non CE) they will no longer be required to take much of the engineering core at our university. This includes theoretical modern physics, and mechanical Phys, as well as electrical phys and Circuits. Gads.. and a 'different' version of CalcI/II/II.. no Diff eq, no linear Alg... What's left, just programming/algorthims and computing concepts? Ouch... oh well. I suppose it is more focused on industry requirements now (Biomedical informatics etc) *Shrug*


Last edited by elyk1212 on Mon Dec 24, 2007 2:01 am; edited 1 time in total

#147519 - keldon - Sat Dec 22, 2007 1:50 am

Well I did computer science and am now a C++ programmer! We did have come C based modules in the course, but I can't see how learning it well/completely is useful to computer science. There are many modules where there isn't even any programming but I'll bet your socks they are useful for programming in some way!

Why Java is chosen as the weapon of choice in a lot of computer science courses is simple; there's a lot less to have to worry about so from a teaching perspective you can get to the point a lot quicker.

However I feel that one of the major downsides to teaching with Java is that people are more likely to adopt more memory unfriendly algorithms, simply because they're easier to write. Also the length storing arrays, memory ignorant containers, String class, and garbage collector can grow a student who thinks very high level, but totally ignorant of the stuff that Java's API and VM hide!

#147525 - sajiimori - Sat Dec 22, 2007 4:11 am

That's my only point, keldon -- I don't think C has to be standard curriculum, in principle, but it sucks that so many students leave school without an understanding of what's going on under the hood.

#147527 - elyk1212 - Sat Dec 22, 2007 5:17 am

Quote:

many modules where there isn't even any programming


Yeah, most of my grad classes are like that, except for occasional programs (and the other exception is graphics, there are loads of theory and programming there).

I guess It isn't "necessary" to learn all C/C++, since there are so many facets of CS/CE and problem solving in general, but just weird to see it all change. Yeah, there's no need to know "all" of any language, I think. But there is a real industry demand for C/C++ experience in some areas, even in the electrical engineering. Or at least engineers that can program at a low level.

What happens when we develop a new architecture? Someone makes an ASM to tie to OP codes... then later (magic of YACC grammars and sweat ,etc) there is a C compiler. With some interesting exceptions, they're not putting Java or scheme,etc on these embedded test boards etc.. Just too high level.

Also, I think this tends to muddy the concepts of memory organization and (as mentioned), what really "goes on". Maybe.... You will see this shortening the gap between IT folk and the CS.. maybe (?). Scary.... hope not though.

Eh... sorry for the off topic stuff. This is like bringing up politics or religion or something, when it comes to comp language choices. The discussion could go on forever, LOL.

#147532 - keldon - Sat Dec 22, 2007 10:52 am

Well what our course did to help was to give us modules on Operating Systems Design, so we used C and Java to develop memory managers and message passing systems.

But in all honesty Computer Science isn't really about getting into the industry (IMO), it's really geared towards research and people who have an academic interest. However it's an odd one, I couldn't say whether CS is a good choice or not for someone who wants to pursue a software development career. One of my colleagues has this view - as far as he's concerned CS has done sod all for his programming.

If you want to get into the industry I think SE might actually be the more logical choice! But then again it all depends on what field you're interested in. The vision, graphics and sound department are all C (and maybe C++).

Actually now I come to think of it they gave me some false advertising lol

#147558 - theguy43 - Sun Dec 23, 2007 2:32 am

ok technically.. I have a Fine Arts Degree..

that doesn't stop me from know over 13 different programming languages, including c/c++, PHP, UScript, and even a bit of Java. Most of them self taught.

I was in a Computer Science & Digital Electronics Honours program, but turns out I have math tests. plus like Keldon, I learned that it doesn't lead towards the game industry. So I went into Art to round out a good portfolio.

I simple forgot if it was C or C++ that had classes. So thanks to those who helped out... I am still programming on the DS, and by the new year I should have a few demos that I'd be willing to post in the forum here.

and btw... Computer Science is all about theory, it doesn't really matter what language it is in.
_________________
-Theguy

#147591 - elyk1212 - Mon Dec 24, 2007 1:58 am

Cool to see others with art background! I suppose that can be more common in the Game industry (which I am unfortunately not part of). Funny enough, I started in art growing up,... even did art honors classes throughout HS and moved to engineering a little later in life. I suppose that is why I'm so interested in game development. I am sure your ed path leads to pretty great game ideas. Honestly engineering drove loads of my creativity (and energy) out the window lol.

Just to be clear, I wasn't saying anything bad about your education or anything, art's totally awesome. Also, I forget many parts of languages, especially if they lay dormant in my usage.. I think everyone has done this. Indirectly, this brought up a slightly off topic subject that is hot in the minds of students and prof at our university: Many completing the CE/CS programs, don't seem to know C/C++ or lower level languages (including general ASM and memory concepts). At times, I am included in this statistic. This wasn't the case for many past graduates. CE had about 70% focus on CS classes, so I am in tune with CS Academia to some degree.

Quote:
it doesn't really matter what language it is in.

You may be right for some career paths. However, language curriculum changes focusing on very high level abstractions seem to have led to much confusion on core computing concepts. These choices matter, in that they can lead to different ways of thinking. For instance, you would not program the same way in a purely functional lambda calculus based language, e.g. scheme, as compared to an imperative language. Just the same is true if you program with solely Java (or other memory managed languages), you would miss out on many Cache organization and memory management topics, as you don't "get your hands dirty" enough with the material, so-to-speak. Therefore, their way of thinking while programming may not consider these topics if not forced to implement them directly in some way.. Anyway, it is just a hot topic right now... and it really had nothing to do with your post. That's my bad.

I look forward to seeing your Demos/Games. When I finally pick up a DS, I can play them :) . Yeah, I am a bit behind.

Happy Holidays, all.

#147627 - sajiimori - Mon Dec 24, 2007 10:34 pm

(Scheme is not purely functional -- its culture and standard library are just oriented toward functional programming.)

#147645 - elyk1212 - Tue Dec 25, 2007 6:00 am

LOL... Ops.. Yes, you're right, that isn't exact. But the closest-to-functional subset of Lisp I could think of. Never used Haskell or the like, but who does? ;)

#147810 - sajiimori - Fri Dec 28, 2007 8:52 am

I don't know anyone who uses it professionally, but it may be the closest thing to the future of programming, considering the drive toward parallelism. Exciting stuff, actually!

#148135 - Miked0801 - Wed Jan 02, 2008 8:01 pm

Bah, humbug! ;)

#148138 - wintermute - Wed Jan 02, 2008 8:22 pm

I say humbug too :P

Allegedly Erlang is the way of the future for parallelism. Dodgy OU 70s style video too - http://video.google.com/videoplay?docid=-5830318882717959520
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#148142 - sajiimori - Wed Jan 02, 2008 9:15 pm

Erlang is along the same lines, but designed for immediate practical use, whereas Haskell is more of an environment for language research.

Erlang shows that the basic idea works (rather awesomely), and meanwhile Haskell continues to extend the idea with novel techniques such as nested data parallelism.

Edit: Link!
http://www.londonhug.net/2007/09/25/nested-data-parallelism-video-returns/