static members n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Static Members PowerPoint Presentation
Download Presentation
Static Members

Loading in 2 Seconds...

play fullscreen
1 / 6

Static Members

100 Vues Download Presentation
Télécharger la présentation

Static Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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(); }