using a header file across multiple files

So say I create a header file which contains a list of structs, and I want to use these structs through out my source and some of my classes... how would I accomplish this?

When I try to do it via #include, I get re-definition errors, due to the nature of #pragma once. If I switch to #ifndef then I lack defenitions in files other than the source.

Is there a way to define things such as structs across multiple files, which doesn't lead to re-definition errors, and doesn't involve manually re-created all the structs for each file?
Last edited on
Header:

1
2
3
4
5
6
7
8
9
#ifndef YOURHEADERNAME_H_INCLUDED
#define YOURHEADERNAME_H_INCLUDED

struct YourStruct
{
    // define your struct here
};

#endif 


You can include this header in as many source files as you want.

Just keep global variables out of your header files (and out of your program -- they're a mess)

See this for more:

http://www.cplusplus.com/forum/articles/10627/
Last edited on
Nevermind... The problem was in the header file... forgot to close the last struct with a ;...

/facepalm
Last edited on
Topic archived. No new replies allowed.