1 / 6

Static Members

Static Members. Static data Members. When a data member is declared as static Only one copy of the data is maintained for all objects of the class Static data members are not part of objects of a given class type The declaration of a static data member is not considered as definition

luna
Download Presentation

Static Members

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Static Members

  2. Static data Members When a data member is declared as static Only one copy of the data is maintained for all objects of the class Static data members are not part of objects of a given class type The declaration of a static data member is not considered as definition Static data member can be defined using the scope resolution operator (::) out side the class

  3. Static data Members single copy is shared by all objects of the same class Created before creating the objects of the class Initial value of static data is 0 class sample { static int a;//declaration }; int sample::a;//definition a member is 0

  4. Static data Members Questions 1)demonstrate automatic initialization of static variable 3) sum of first n numbers 4)display how many instances of a class object has been created

  5. Static Member Functions Static member functions can access only static member data Non static member function can access all member data including static data member Static member function cannot declared as virtual Static function can be defined by using the keyword static before the function return type Syn Static data type function name(argument list) { function body; }

  6. Static Member Functions Static member functions cannot be invoked with class object Static member functions can be invoked with class name and :: class sample { static int a; static void display(); } int sample ::a=10; void sample:: display(){----} main() { sample::display(); }

More Related