Thread: Makefiles
View Single Post
  #9   (View Single Post)  
Old 21st October 2008
JMJ_coder JMJ_coder is offline
VPN Cryptographer
 
Join Date: May 2008
Posts: 464
Default

Huh? I do use the header files to put whole classes. I didn't know that was a no-no. So I should have the class definition in one file (header file) and the class methods in another file (cpp file)? So for instance, in the project I have a thing class (actually, the professor wrote it) - so it should be structured like this?

thing.h
Code:
class thing {
	
	public:
		thing(int, int, char);
		thing();
		int getx();	/* x coordinates of character */
		int gety();	/* y coordinates of character */
		char get_symbol();

	protected:
		int x, y;	/* where thing is */
		char symbol;	/* what thing is represented by */
};
thing.cpp
Code:
#include "thing.h"

thing::thing() {}

thing::thing(int xinit, int yinit, char s) 
{
	x = xinit;
	y = yinit;
	symbol = s;
}

int thing::getx()
{
	return x;
}

int thing::gety()
{
	return y;
}

char thing::get_symbol()
{
	return symbol;
}


If that is so, what do I include in the main.cpp file - thing.h; thing.cpp; both; neither?


Also I do have some global function prototypes in the header file, and some defines:

Code:
#include <curses.h>
#include <math.h>

#define POSX 50
#define POSY 20
#define DOORTOP 7
#define DOORBOTTOM 13

/* forward declarations */

class agent;
class dot;
class guard;
class hackbot;
class slashbot;
class thing;

/* function prototypes */

void draw(WINDOW*, thing[], hackbot, slashbot, dot);
bool check_wires(agent, thing[]);
bool collide(agent, agent);

Should these be in a header file?
__________________
And the WORD was made flesh, and dwelt among us. (John 1:14)
Reply With Quote