# Header File Including Once/Also Inline

## Recommended Posts

chbrules    170
Is there a difference between using: #pragma once and #ifndef VAR #define VAR #endif ? If so or not, is there a preference of some sort for some reason? Also I have a quick question about inline function, say I make a prototype in a class, do I just use the inline keyword there in the prototype, or do I have to use it where I define it too?

##### Share on other sites
chbrules    170
Another question @_@

I get linker error when I try to create an object of a struct I made in global scope. Is then when you're supposed to use the extern keyword? It compiles fine just w/ the struct code, but as soon as I make an object of it, linker errors pop up all over.

##### Share on other sites
Drew_Benton    1861
Take a look at this thread in regards to your first question. It was asked a few hours ago.

As for your second question, you will need to make it extern in your header file, then define it once in a .cpp file that uses theat .h file. I think you are getting multiple symbol linker errors correct?

- Drew

##### Share on other sites
chbrules    170
Thanks! Well now I've tried to do this in a header:

extern struct Index
{
int iIndex_num;
char *filename;
};

And then I go ahead and define an object of it in another .cpp:

Index index;

Then I get these errors:

globals.h(20) : warning C4091: 'extern ' : ignored on left of 'Index' when no variable is declared
main.cpp(74) : warning C4101: 'index' : unreferenced local variable

##### Share on other sites
Endurion    5411
On a simple struct declaration you shouldn't need any "extern" keyword. You can define the same struct several times, if it doesn't differ the compiler won't complain.

If you're trying to define a variable named "index" of this struct you need to put the index on the end of the struct declaration:

extern struct{   int iIndex_num;  char *filename;} Index;

##### Share on other sites
chbrules    170
Firstly, I'm creating a game engine w/ SDL.

Well I've defined this struct to use in a couple vectors to index all my texture, maps, and other script files. The dictionary table will be in the map file format I've created, kind of like a compression format's dictionary table. It will help me keep the file sizes smaller rather then having to have the images file name for every tile of the map. Oh ya, it's a tile-based map scenario. =) I'm so sloppy with explanations.

Zahlman    1682

## 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