a problem with static declarations

A

artun

Hello all,

I want to ask for advice in using static declarations:

I am working on an object oriented library. and a software project that
makes use of that library.

I use a static private method in a class of the library for some
purpose. This method uses some of the static data members of the same
class. I can compile the library without any compile or linking errors.

When I link the library in the software project, I receive a link error
that the static data member of the class is not resolved.

Can anyone help me what can be reason of the error?

Thanks all...
 
R

roberts.noah

artun said:
When I link the library in the software project, I receive a link error
that the static data member of the class is not resolved.

Chances are you didn't define it.

some.h
class X
{
static int y; // *declaration*
};

some.cpp

int X::y; // *definition*

When you compile as a lib it works ok because this allows you to later
define this member in some other object file. Libraries can have
unresolved symbols or they wouldn't work. Once you try to make a
complete program though, all symbols in all libs must resolve somewhere
in the entire thing or you'll get the error you got.
 
D

David Harmon

On 4 Dec 2005 11:03:36 -0800 in comp.lang.c++, "artun"
When I link the library in the software project, I receive a link error
that the static data member of the class is not resolved.

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"#[10.11] Why are classes with static data members getting linker
errors?" It is always good to check the FAQ before posting. You
can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top