[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

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.
 
0
e6694811
Asked:
e6694811
  • 3
1 Solution
 
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
 
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now