question about header files
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
So you are writing the class declaration in the header file, foo.h, like:
then you have the class member function difinitions in a seperate cpp file, foo.cpp, like so:
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:
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.
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.
They don't have to be.. could do
#include "MyFolder\Spiffy.h"
Note also that if you use global variables do it like so
#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;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement