C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

static data member

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Jan 29, 2004 3:13 pm    Post subject: static data member Reply with quote



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 GessoidMachine::Machine::resolution"
(?resolution@Machine@GessoidMachine@@0V?$vector@UResolution@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;
};
----------------------


Back to top
John Carson
Guest





PostPosted: Thu Jan 29, 2004 3:29 pm    Post subject: Re: static data member Reply with quote



"<- Chameleon ->" <cham_gss (AT) hotmail (DOT) NOSPAM.com> wrote

Quote:
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 GessoidMachine::Machine::resolution"

(?resolution@Machine@GessoidMachine@@0V?$vector@UResolution@GessoidMachine@@

V?$allocator@UResolution@GessoidMachine@@@std@@@std@@A)
Quote:
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 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)


Back to top
Guest






PostPosted: Thu Jan 29, 2004 3:33 pm    Post subject: Re: static data member Reply with quote



Aaaaaaaaa!!!!!!

How much idiot I am?


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.