Buy Geeky T-Shirts and Hoodies


C++: Classes & Objects-2

Private Member Functions:

A private member function can only be called by another function that is a member of its class.

An object cannot invoke a private function using the dot operator.

     class demo{
                   void read(); 
                   void update();
if s1 is object; //won't work

   void sample::update(){

Memory allocation for Objects:

The member functions are created and placed in the memory space only once when they are defined as a part of a class specification.

No seperate space is allocated for member function when objects are created.

Only space for member variables is alocated seperately for each object, because the member variables will hold different data values for different objects.

Static Data Member:

It is initialized to zero when the first object of its class is created. no other initialization is permitted.

Only one copy of that member is created 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.

They are associated with the class itself rather than with any class object, they are also known as class variables.

They are like non-inline member functions as they are declared in  a class declaration and defined in the source file.

       class sample{
                         static int count;
int sample::count=10;

     int main(){

 Static Member Function:

A static function can have access to only other static members declared in the same class.

A static member function can be called using the class name instead of object.

   class-name:: function-name

                   < Happy Coding >


In Association with


Buy Geeky T-Shirts and Hoodies