Jump to content
  • Advertisement
Sign in to follow this  
chbrules

Header File Including Once/Also Inline

This topic is 4873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!