static data members and static member functions n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Static Data Members And Static Member Functions PowerPoint Presentation
Download Presentation
Static Data Members And Static Member Functions

Loading in 2 Seconds...

play fullscreen
1 / 13

Static Data Members And Static Member Functions - PowerPoint PPT Presentation


  • 107 Views
  • Uploaded on

Static Data Members And Static Member Functions. Topics to be discussed. Static Data Members Example of Static Data Member Static Member functions Example of Static Member Function. Static Data Members.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Static Data Members And Static Member Functions' - tobias-richard


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
static data members and static member functions
Static Data Members

And

Static Member Functions

topics to be discussed
Topics to be discussed
  • Static Data Members
  • Example of Static Data Member
  • Static Member functions
  • Example of Static Member Function
static data members
Static Data Members

are data objects that are common to all objects of a class.they exist only once in all objects of this class and are used when the information is to be shared

BACK

3

It is initialized to zero when the first object of its class is created.

There is exactly one copy of a static member for the entire class and is shared by all the objects of that class.

It is visible only within the class,but its lifetime is the entire program.

When a static data member is declared private,the non-member functions can not access this member.

Static variables are normally used to maintain values commom to the entire class.For example,a static data member can be used as a counter that records the occurrences of all the objects.

slide7

Here above in the program

int item::count;

is the definition of the Static Data Member

  • The Static Variable count is initialized to when the objects are created.The count is incremented whenever the data is read into an object.Since the data is read into objects three times,the variable count is incremented three times because there is only one copy of count shared by all the three objects and all the three output statements cause the value 3 to be displayed.

BACK

static member functions
Static Member functions

BACK

8

  • It is the special member function that is declared static hasthe following features:
    • It cannot access non-static data members or non-static member functions of the class (because the object may not exist when the function is called)
    • A static function can have access to only other static members(functions or variables) declared in the same class.
    • static data members and static member functions exist independently of any objects of a class, i.e., when a static member function is called, there might not be any objects of its class in memory
    • A static member function can be called using the class name(instead of its objects) as follows:

classname::functionname;

slide12

The Static function showcount() displays the number of objects created till that moment.A count of number of objects created is maintained by the static variable count.

  • The statement

code=++count;

is executed whenever setcode() function is invoked and the current value of count is assigned to code.Since each object has its own copy of code,the value contained in code represents a unique number of its objects

BACK