question about header files

Started by
2 comments, last by Jemburula 18 years, 10 months ago
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
Advertisement
So you are writing the class declaration in the header file, foo.h, like:
class foo{private://stuffpublic: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.
so do all the files have to be in the same folder or something like that?
They don't have to be.. could do

#include "MyFolder\Spiffy.h"

Note also that if you use global variables do it like so

/* Foo.h */extern bool Bar;// .../* Foo.cpp */bool Bar = true;
What we do in life... Echoes in eternity

This topic is closed to new replies.

Advertisement