What is the use of static functions?

Answer Posted / v venkatesh

The differences between a static member function and non-
static member functions are as follows.

A static member function can access only static member
data, static member functions and data and functions
outside the class. A non-static member function can access
all of the above including the static data member.

A static member function can be called, even when a class
is not instantiated, a non-static member function can be
called only after instantiating the class as an object.

A static member function cannot be declared virtual,
whereas a non-static member functions can be declared as
virtual

A static member function cannot have access to the 'this'
pointer of the class.
The static member functions are not used very frequently in
programs. But nevertheless, they become useful whenever we
need to have functions which are accessible even when the
class is not instantiated.

Is This Answer Correct ?    70 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is encapsulation in c++ with example?

555


Can we make any program in c++ without using any header file and what is the shortest program in c++.

587


Difference between overloaded functions and overridden functions

552


Why null pointer is used?

555


What is singleton pattern in c++?

523






Why do we use pointers in c++?

571


Are vectors faster than arrays?

551


How do c++ struct differs from the c++ class?

571


Write about the scope resolution operator?

594


Explain all the C++ concepts using examples.

662


Why cout is used in c++?

543


When are exception objects created?

581


What are the 2 main types of data structures?

567


Is c++ an oop?

564


What is the function of I/O library in C++ ?

633