4.07 Static Member Variables and Functions in C++

Darshan University
Darshan University
6.2 هزار بار بازدید - 6 سال پیش - Learning static Data members/variables with
Learning static Data members/variables with the example. Static member functions.

A static data member is useful,
when all objects of the same class must share a common information
- Just write static keyword prefix to the regular variable
- It is initialized to zero before  first object of a class created
- Only one copy is created for each object
- Its lifetime is an entire program
Static members are declared inside the class and defined outside the class. It is initialized to zero when the first object of its class is created. It is visible only within the class but its lifetime is the entire program. Static member functions can access only static members of the class.
Static member functions can be invoked using the class name, not object. There cannot be a static and non-static version of the same function. The member functions are created and placed in the memory space only once at the time they are defined as part of a class specification. No separate space is allocated for member functions when the objects are created. Only space for member variable is allocated separately for each object because the member variables will hold different data values for different objects.

GTU - Computer Engineering (CE) - Semester 4 - 2140703 - Object Oriented Programming with C++ - Concepts of C++ - Introduction to Object Oriented Programming

Object-Oriented Programming with C++ PPTs are available here: http://www.darshan.ac.in/DIET/CE/GTU-...

This video is recorded by Prof. Rupesh Vaishnav ([email protected], +91-9428037452) at Computer Engineering Department of Darshan Institute of Engineering & Technology, Rajkot as per GTU Syllabus.

Darshan Institute of Engineering & Technology, Rajkot is a leading institute offering undergraduate, graduate and postgraduate programs in engineering. The Institute is affiliated to the Gujarat Technological University (GTU) and approved by the AICTE, New Delhi.

Visit us: http://www.darshan.ac.in
Write us: [email protected]
Facebook: Facebook: DarshanInstitute.Official
Twitter: Twitter: darshan_inst
Instagram: Instagram: darshan_inst
6 سال پیش در تاریخ 1397/02/13 منتشر شده است.
6,224 بـار بازدید شده
... بیشتر