Sign in to follow this  
rayce

question about header files

Recommended Posts

i have trouble making header files in Dev C++ 4.9.8.0 i open a blank source file, type in a class def, open another, type in it's function defs, and try to use it. guess what. i need someone to tell exactly what to do, step by step, to accomplish this thanks

Share this post


Link to post
Share on other sites
So you are writing the class declaration in the header file, foo.h, like:

class foo
{
private:
//stuff
public:
foo();
~foo();

void blah();
}


then you have the class member function difinitions in a seperate cpp file, foo.cpp, like so:

#include "foo.h"

foo::foo()
{
//init stuff
}

foo::~foo()
{
//clean up stuff
}

void foo::blah()
{
//function stuff
}


Note- you have the inclusion of foo.h that is in the projects local directory (hence "foo.h" as opposed to <foo.h>)

then you have a seperate file, say main.cpp, that has:


#include "foo.h"
foo *instfoo = NULL;
int main()
{
instfoo = new foo();

//stuff
}


Note- you include foo.h pointing to local directory and you create an instance of foo.

You should have this kind of setup to get modular C++ to work correctly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this