This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

static declaration


Hi,
	I have been having problem with the use of the static keyword.  
The first problem I have is when I try to create a static class member 
variable.  Everything compiles correctly, but upon linking where ever the 
static member variable is used in my code the linker complained about 
there being an undefined reference to the static member variable.  I 
thought this might be some other problem, but upon removal of the 
static key word the program compiles and links fine and runs as 
expected.  The second problem I encounter is when trying to declare
a class member function (that subtracts one global variable from 
another and returns the differenct) as a static member function.  Upon
compiling the class I get an error saying I cannot declare member 
function 'static int Packet::GetMessageSpace()' to have static linkage.
If I remove the keyword static from the function declaration in both the 
header file and the c++ file, and change calls to the function from
Packet::GetMessageSpace() to myPacket.GetMessageSpace()
(and myPacket is just an object of type Packet)everything compiles 
and links correctly and the program functions correctly.  I am running
RedHat 9 on an intel machine.  I would appreciate any help you can 
give me as to the problems I have received, as I expect I have just 
overlooked some obvious step to correct these problems.

Thank you,
Scott Rushfeld


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]