Re: Newbie making a roguelike
- From: Daimones <pcl3385@xxxxxxxxx>
- Date: Thu, 16 Jul 2009 05:51:15 -0700 (PDT)
On Jul 16, 2:42 am, Mingos <dominikmarc...@xxxxxxxxx> wrote:
On 15 Lip, 20:35, Daimones <pcl3...@xxxxxxxxx> wrote:Newb Question: What's the difference between .h and .hpp files?
Also I must be mis-understanding something, because I have a Move()
function in my roguelike.cpp, which references my hard-coded dungeon
array which is in the same file. I'm trying to move these functions to
another file and not exactly sure how to go about that, do they have
to be in a class? Because I just put the functions into another .cpp
file and they can't reference the global dungeon array.
Always declare classes and structs and such in your .h/.hpp files.
The .cpp files should only contain the actual code, ie, the
implementation of what you declared. If you need a global variable/
object/whatever, do this:
I'm assuming .hpp is where you would store a class? Since it has
source, and also declarations?
in the map.hpp:
extern int myMap[80][60];
and in the map.cpp:
#include "map.hpp"
int myMap[80][60] = {/*your hardcoded map goes here*/};
Ahh okay, that's what has to be done, I was unaware of using the
extern command to implement a global variable.
Remember that if you want to reference myMap from another .cpp file,Yea, I sort of started that already, I have define.h with all my
it has to bear the preprocessor command #include "map.hpp". This way
you should be OK.
When there are quite a few .hpp files to keep track of, make an
includes.hpp file and put all the #include commands there in the order
you need. Then, each .cpp file will only need this: #include
"includes.hpp". Easy.
#defines in them which is included in my headers.h file.
One more thing. I may be misunderstanding you, but did you say thatIt was my own function named Move(), not a global C function. Sorry
Move() is a function? A global function? That's C, not C++. You can do
it this way, sure, but it's much more handy to make it a method within
a class. Declare the class and all its methods in the .hpp and then
write the implementation in the .cpp file. Trust me, it's the way to
go :).
for the confusion.
Best of luck with your roguelike!
Mingos
Thanks!
.
- Follow-Ups:
- Re: Newbie making a roguelike
- From: Paul Donnelly
- Re: Newbie making a roguelike
- From: pdpi
- Re: Newbie making a roguelike
- References:
- Newbie making a roguelike
- From: Daimones
- Re: Newbie making a roguelike
- From: Mingos
- Newbie making a roguelike
- Prev by Date: Re: Newbie making a roguelike
- Next by Date: Re: Newbie making a roguelike
- Previous by thread: Re: Newbie making a roguelike
- Next by thread: Re: Newbie making a roguelike
- Index(es):
Relevant Pages
|
Loading