Sign in to follow this  

Linking extern class instances

This topic is 2080 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

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

This topic is 2080 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.

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