473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

static data member

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
2 7609
"<- 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
Aaaaaaaaa!!!!!!

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
8
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
1
by: mangalalei | last post by:
A static data member can be of the same class type as that of which it is a member. A nonstatic data member is restricted to being declared as a pointer or a reference to an object of its class. ...
1
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of...
10
by: shanknbake | last post by:
I'm getting the following compile-time error: error C2352: 'Person::getCount' : illegal call of non-static member function Here is my getCount function declaration:...
6
by: subramanian100in | last post by:
why can't a static member function be declared as const ? We can declare a non-static member function as const, to indicate that it does not modify the non-mutable data members. In the same way, is...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.