Solved

Why is class public member definition repeated?

Posted on 2013-06-07
2
389 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

839 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