?
Solved

Why is class public member definition repeated?

Posted on 2013-06-07
2
Medium Priority
?
392 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 1400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
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.
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

800 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