Sign in to follow this  
Ashaira

Linking extern class instances

Recommended Posts

Ashaira    105
Im new to using extern variables and after trying to extern my Scene Manager and Resource Manager i end up getting linking errors.

The .h where i put the extern class instances looks like this
[code]#pragma once
#include "SceneManager.h"
#include "ResourceManager.h"
extern CResourceManager *Resources;
extern CSceneManager *Scene;[/code]

and the declarations are in a different .cpp

but wherever i included the above hearder i get linking errors. did i make some mistakes in making the header?

Share this post


Link to post
Share on other sites
SiCrane    11839
The header is fine, but they only include declarations. That is, they tell the compiler that at some point someone is going to define those variables. Now you need to go and do just that. In a single source file you need to define the global variables without the externs. In your case you'd have:
[code]
CResourceManager *Resources;
CSceneManager *Scene;
[/code]

Share this post


Link to post
Share on other sites
Ashaira    105
oh. riiiiiiiiiiight. thnx a lot. forgot i had to define them without the extern. i was just constructing them in the cpp without defining them. thnx a lot. works perfectly.

"Dam whoever invented singleton"

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this