What is the use of static functions?

Answers were Sorted based on User's Feedback



What is the use of static functions?..

Answer / 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

What is the use of static functions?..

Answer / dee

they are not associated with "this" pointer since it can be
called without object.they can acees only static varibales.

Is This Answer Correct ?    55 Yes 11 No

What is the use of static functions?..

Answer / khan

Static member functions give internal linkage. The function
declared as static is not visible outside the file in which
it is declared. It is not associated with "this" pointer and
it can be invoked using class name instead of depending on
individual object. It can access only static members of the
class.

Is This Answer Correct ?    13 Yes 4 No

What is the use of static functions?..

Answer / manu

Static member functions have external linkage. These
functions do not have this pointers. As a result,

They cannot access nonstatic class member data using
the member-selection operators (. or –>).

They cannot be declared as virtual.

They cannot have the same name as a nonstatic function
that has the same argument types.

They are useful as they donot have access to this pointer
and so they can be called even though the class is not
instantiated.

Is This Answer Correct ?    10 Yes 2 No

What is the use of static functions?..

Answer / anh vu

A static function member can be used to provide utility
functions to a class. For example, with a class representing
calendar dates, a function that tells whether a given year
is a leap year might best be represented as a static
function (DateTime.IsLeapYear). The function is related to
the operation of the class but doesn't operate on particular
object instances (actual calendar dates) of the class.

Is This Answer Correct ?    15 Yes 8 No

What is the use of static functions?..

Answer / sumanta pattanayak

static function is used to call static variable or class
variable...rather than that without creating the class
object we can access the static function by
classname.staticfunctionname.....THIS cannot be used inside
static function.

Is This Answer Correct ?    6 Yes 1 No

What is the use of static functions?..

Answer / reejusri

Static function is basically used in creating factory
objects.
You can make your constructor private and expose static
function. And user can use the static methods to create the
object of that class.
Using NONSHARABLE_CLASS you can restrict the usage of
static functions/method also.

Is This Answer Correct ?    15 Yes 16 No

What is the use of static functions?..

Answer / amit

Amit Srivastava:
What i think , static functions are used with the conditions
where there is no need to occupy RAM memory unnecessarily.
As ,other than Static functions are attached with the object
and ready to use memory space as and when a object of that
class is instantiated.But Static functions are having only
one address as they are independent of Objects.

Is This Answer Correct ?    4 Yes 7 No

What is the use of static functions?..

Answer / sanish joseph

If we r using Static functions all the objects will get only
a single copy of dat function,means der wil b only one copy
of dat function.
static functions will contain only static variables.

Is This Answer Correct ?    17 Yes 27 No

What is the use of static functions?..

Answer / priya

static word meaning it cannot be changed.so when we use
static in the function it cannot be changed

Is This Answer Correct ?    6 Yes 73 No

Post New Answer

More C++ General Interview Questions

What information can an exception contain?

0 Answers  


Difference between class and structure.

0 Answers  


What is the type of this pointer in c++?

0 Answers  


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

0 Answers  


Why can’t you call invariants() as the first line of your constructor?

0 Answers  






What is flush programming?

0 Answers  


What are the various access specifiers in c++?

0 Answers  


What is function prototyping?

0 Answers  


Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).

0 Answers  


catch(exception &e) { . . . } Referring to the sample code above, which one of the following lines of code produces a written description of the type of exception that "e" refers to? a) cout << e.type(); b) cout << e.name(); c) cout << typeid(e).name(); d) cout << e.what(); e) cout << e;

2 Answers   Quark,


What jobs can you get with a c++ certification?

0 Answers  


How many characters are recognized by ANSI C++?

0 Answers   Hexaware, NIIT,


Categories