By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

static data member

P: n/a
what is meaning of this? (MS VC++ .NET)
----------------------
Linking...
machine.obj : error LNK2001: unresolved external symbol "private: static class std::vector<struct GessoidMachine::Resolution,class
std::allocator<struct GessoidMachine::Resolution> > GessoidMachine::Machine::resolution"
(?resolution@Machine@GessoidMachine@@0V?$vector@UR esolution@GessoidMachine@@V?$allocator@UResolution @GessoidMachine@@@std@@@std@@A)
machine.obj : error LNK2001: unresolved external symbol "private: static struct SDL_Surface * GessoidMachine::Machine::screen"
(?screen@Machine@GessoidMachine@@0PAUSDL_Surface@@ A)
machine.obj : error LNK2001: unresolved external symbol "private: static int GessoidMachine::Machine::resolution_index"
(?resolution_index@Machine@GessoidMachine@@0HA)
..\Debug/main.exe : fatal error LNK1120: 3 unresolved externals
----------------------

The error is in this code: (All member functions & data are static because I want only one instance of "Machine" in my project and I
want access in any data member without this->
----------------------
class Machine {
public:
static member1(arg1, arg2);
static member2();
.......
private:
// handle all resolutions supported from system
static vector <Resolution> resolution;
static int resolution_index;
static SDL_Surface *screen;
};
----------------------
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message
news:bv**********@nic.grnet.gr
what is meaning of this? (MS VC++ .NET)
----------------------
Linking...
machine.obj : error LNK2001: unresolved external symbol "private:
static class std::vector<struct GessoidMachine::Resolution,class
std::allocator<struct GessoidMachine::Resolution> >
GessoidMachine::Machine::resolution"
(?resolution@Machine@GessoidMachine@@0V?$vector@UR esolution@GessoidMachine@@
V?$allocator@UResolution@GessoidMachine@@@std@@@st d@@A) machine.obj : error LNK2001: unresolved external symbol "private:
static struct SDL_Surface * GessoidMachine::Machine::screen"
(?screen@Machine@GessoidMachine@@0PAUSDL_Surface@@ A)
machine.obj : error LNK2001: unresolved external symbol "private:
static int GessoidMachine::Machine::resolution_index"
(?resolution_index@Machine@GessoidMachine@@0HA) .\Debug/main.exe :
fatal error LNK1120: 3 unresolved externals
----------------------

The error is in this code: (All member functions & data are static
because I want only one instance of "Machine" in my project and I
want access in any data member without this->
----------------------
class Machine {
public:
static member1(arg1, arg2);
static member2();
.......
private:
// handle all resolutions supported from system
static vector <Resolution> resolution;
static int resolution_index;
static SDL_Surface *screen;
};
----------------------


static data members are like member functions: you declare them in the
header file and then define them in the .cpp file. Basically, storage is
allocated for ordinary data members when you define an object of the class.
But static data members are independent of any class object and hence you
need to define them separately in order for storage to be allocated for
them.

Thus your .cpp file needs to contain:

vector <Resolution> Machine::resolution;
int Machine::resolution_index;
SDL_Surface *Machine::screen;

Note that you must omit the static keyword in these definitions.
--

John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2

P: n/a
Aaaaaaaaa!!!!!!

How much idiot I am?
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.