#findef/#define in headers + cpp for definition.

I have a header file that i'd like to keep the definitions in another .cpp file. How can I do that with #ifndef/#define ... or is it even needed when definitions are in a seperate .cpp file?
Like this?

a.h
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef _A_
#define _A_

class A
{
public:
//
private:
//
};

#endif 


a.cpp
1
2
#include "a.h"
// Definitions of A-class 
Last edited on
Yes, what if I also seek to use this in, let's say Main.cpp?
Last edited on
You include header file (this time a.h) in the main.cpp. Then you just compile with:
g++ a.cpp main.cpp -o program
Last edited on
you should separate the Abstract Data Type to you main program.

you will just:

#include "a.h"



Can you please elobare a bit? I have three files

header file (.h)
#ifndef/#define part
...Class and method prototypes...
#endif

definition file (.cpp)
#include (said header file)

...Define the functions

and lasty I have main.cpp that I want to use the defined functions. Is there a way or can I just remove the #ifndef/#define/#endif part?

eraggo, is that for another compiler? I use VS2008.
Last edited on
Yes you can remove #'s (of course not in #include-statelement). Them just makes so if file is already included it won't do it again.

I use g++ as compiler under Linux.
Last edited on
I found the sinner giving me errors -- declaration of global variable under the namespace in the header. Is it okay if I only declare it in the cpp defining? For I won't have to deal with it directly from main.
Topic archived. No new replies allowed.