Visibility of objects across files

Nov 21, 2012 at 8:02pm
I've been stuck for some time on an error regarding the visibility of objects declared in one file in other files in my project. I'm using VCE 2010, and here are a few relevant snippets:

Player.h
1
2
3
4
5
6
7
#ifndef player_h
#define player_h
class Player
{
// . . . .
}player;
#endif 


Player.cpp
1
2
3
4
5
6
#ifndef Player_cpp
#define Player_cpp

#include"Player.h"
// . . . .
#endif 


Main.cpp
1
2
3
4
5
6
#ifndef ShadesOfBlue_cpp
#define ShadesOfBlue_cpp
#include"Player.h"
extern Player player;
// . . . .
#endif 


All of my errors stem from the fact that Main does not recognize the player object. Thanks in advance for any help.
Last edited on Nov 21, 2012 at 8:02pm
Nov 21, 2012 at 8:52pm
maybe just define the class in Player.h, Player.cpp and instance the object in Main

Player.h
1
2
3
4
5
6
7
#ifndef player_h
#define player_h
class Player
{
// . . . .
};
#endif  


Main.cpp
1
2
3
4
5
6
#ifndef ShadesOfBlue_cpp
#define ShadesOfBlue_cpp
#include"Player.h"
Player player; // global to Main.cpp
// . . . .
#endif  

Nov 21, 2012 at 8:53pm
You also don't need to have header guards in the source files.
Topic archived. No new replies allowed.