Solved

Why is class public member definition repeated?

Posted on 2013-06-07
2
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 350 total points
ID: 39229196
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
 
LVL 1

Author Closing Comment

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

Great explanation!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

724 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