Solved

Why is class public member definition repeated?

Posted on 2013-06-07
2
385 Views
Last Modified: 2013-06-07
Please consider following class:

class SomeTask
{
 
  public:
     SomeTask();
    ~SomeTask();
    void initialize();
    static unsigned int _tsk;
     
  private:  
    InterfaceTask *_serviceInterface;
    Protocol * _Protocol;
     
    static SomeTask *_instance;  
 
};

Then consider the following:

unsigned int SomeTask::_tsk;


why is public variable _tsk defined twice?  Once inside the class and once outside the class?
0
Comment
Question by:naseeam
2 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 350 total points
Comment Utility
That is defining the static member _tsk. The default, in the absence of assigning a value, will be to initialise it with the default value of that type, in this case that'll be a zero. This is true for all static variables!

Without this line that member is only declared (telling the compiler it exists somewhere) but not actually defined (creating the existence of it).
0
 

Author Closing Comment

by:naseeam
Comment Utility
Oh!  I see.  It's going take some time to transition to c++.  

Great explanation!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
QAction use more than one time. 3 20
Rijndael string encryption in C++ 3 93
PDF library for Delphi 2 89
C++ mouse_event mouse look 7 19
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now