Header File Including Once/Also Inline

Started by
5 comments, last by Zahlman 19 years, 2 months ago
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?
-Conrad
Advertisement
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.
-Conrad
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
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
-Conrad
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;

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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.
-Conrad
*bUrp*

This topic is closed to new replies.

Advertisement