Serializing a static data member


 Is there any chance I can serialize a static data member ?

 Consider the following case.

 class CB:public CA
 {
   protected:
   static UINT m_number;

..... (more data menbers)


  public:

..... (some functions)

  Serialize (Carchive &ar);

....
 }

The function serialize is defined as follows:

void CB::Serialize(CArchive &ar)
{

   
    if (ar.IsStoring())
              ar <<m_number;
    else
             ar >>m_number;

  CA::Serialize(ar);
}


m_number is used to store the amount of  objects of the same class.

When linking the following error occurs:

rror LNK2001: unresolved external symbol "protected: static unsigned int  CB::m_number" (?m_number@CB@@1IA)


Any help ? thanks.
 
e6694811Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
The error has nothing to do with Serialize. You declare the variable but not define it yet.

Put the following line in your .cpp file.

static UINT class CB::m_number = 0;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chensuCommented:
Sorry, it should read

static UINT CB::m_number = 0;
0
e6694811Author Commented:

 I think I have to ommit the word "static" ,right ?
0
chensuCommented:
Right.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.