Learn how to a build a cloud-first strategyRegister Now

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

Why is class public member definition repeated?

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
naseeam
Asked:
naseeam
1 Solution
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
naseeamAuthor Commented:
Oh!  I see.  It's going take some time to transition to c++.  

Great explanation!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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