Skip to main content
gamedev.net
🔒 Locked

C++ Function Help

Started by cloekeysan Feb 4, 2005 at 9:37 AM 4 replies 1k views
Original Post
cloekeysan
cloekeysan
Okay, I've been holding off learning how to program games for like ever. I took some C++ courses in high school and learned the basics (functions, loops, control statements, input/output files, etc...). Now that I'm taking Java in college which is required for my major, I figured I'd start rebuilding my understanding of C++ before I try to do something with directx or opengl. I have been using the following tutorials: http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/groundsup/index They have been extremely helpful bring me up to speed and learn new ideas such as classes and structures. So, I decided to write a text based game that used all of my knowledge just to cement everything in place. After all, if I can't write a game in just text, how am I supposed to do it with graphics? Anyways, I have run into a few problems. I've been trying to keep my main pretty empty. I just want it to control the flow of the game itself. However, if I call a function that is initialized beneath the function I'm calling it in, I get errors. I'm so far into the coding of the game that I can't just rearrange the functions otherwise I'll get more errors. Any ideas on how to get around this besides repiecing my code together? PS: After I finish "Sadie", which is a pet management game, I intend to write a tetris clone or make "Sadie" graphical. Should I be looking for directx tutorials, sdl tutorials, or opengl tutorials?? If possible, where could I find some good beginner tutorials on either of these.
jflanglois
jflanglois
You need to use forward function declaration, like so:

int foo(); // <--- Forward declaration of foo()void bar() {  foo();}int foo() {  // do stuff;}int main() {  bar();  return 0;}



Regards,
jflanglois
cloekeysan
cloekeysan
bah, I forgot about prototyping. Here are some more questions, just syntax though.

It doesn't seem to matter, but should I put my functions after my main or before it? It seems as though it works either way.

I just learned classes. Is it possible to prototype functions that are in classes, or is that already done by the nature of how classes work?
pprice001
pprice001
That is handle by the class declaration (the header file) just remeber to include it

ie

#include "SomeClass.h"

P.
JonnyQuest
JonnyQuest
Quote:
Original post by cloekeysan
It doesn't seem to matter, but should I put my functions after my main or before it? It seems as though it works either way.

It doesn't matter at all. It'll compile to the same object code.

Quote:
I just learned classes. Is it possible to prototype functions that are in classes, or is that already done by the nature of how classes work?

Well, you need to declare all member functions of a class in the
class ClassName{  // declarations here};

block, but outside of that, no.

~phil
~phil

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.