answersLogoWhite

0

Static function are function only visible to other function in same file Function outside the class can access, useful whenever we need to have functions which are accessible even when the class is not instantiated.

User Avatar

Wiki User

17y ago

What else can I help you with?

Continue Learning about Engineering

How do you differentiate between a member function and normal function?

A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.


What facility static gives in class?

Static variables or function provides global view to the application that is u can access a static variable with one or more than one objects of a single class without loosing i.e. reinitializing its value.


What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.


What is the function of static relay?

function of static relay


What is the difference between normal function and static function in c plus plus?

When a function is declared static at file scope, this means the function has internal linkage only. That is, the function is only accessible to the translation unit in which it is declared. This applies to both C and C++. However, we can achieve the same thing in C++ by declaring a (non-static) function in an un-named (anonymous) namespace. Whether this better represents internal linkage or not is merely a matter of taste. In C++ we can also declare static functions inside a class. Static member functions differ from non-static member functions in that they do not have access to a 'this' pointer; they are local to the class, not to objects (instances) of the class. As such, they can be invoked without having to instantiate an object from the class.

Related Questions

What is the Use of static function?

A static function is a member function that is not associated with any instance of the class; it has no this pointer.


What is the pupouse of static function?

A static function, not part of a class, is visible only to other code within the same compilation unit, i.e. the same source file. A static function, part of a class, can only operate on static class data, which is per class data as opposed to per instance data.


How many static function can declare in one class?

It is dependent on the requirement of your usage of the Object of that class


How do you differentiate between a member function and normal function?

A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.


How do you call static methods without using objects?

You can call a static method via an object; the other alternative is to use the class name. A common example is the following, to calculate the exponential function: Math.exp(x) Here, exp() is a static function in the class Math. Note that the class name is used instead of an object.


How is memory allocated to the private-data member function when an object is not created during the calling process?

A class can have both static and non-static data. Static data is local to the class while non-static data is local to each object of the class. It makes no difference whether static data is global, local to a file, local to a function or local to a class (whether public, protected or private), all static data is allocated within the program's data segment along with all constants. As such they are allocated at compile time.


Is a static member function similar to a friend function?

No. To understand how friend functions relate to static functions you first need to understand the three qualities of a normal member function (an instance member function): 1. The function has access to the private aspects of the class in which it is declared. 2. The function is scoped to that class. 3. The function must be invoked on or from within an object of that class. A static function only has the first two qualities (so no instance of the class is required) while a friend function only has the first quality (so is neither scoped to the class nor requires an instance of the class). All three share the first quality only but that alone does not make them similar. It is the qualities they lack that sets them apart.


What is static class?

A static class is a class where all the members are declared static.


What do you understand by keyword 'this'?

"this" can only be used within the body of a non-static member function of a class and refers to the current instance of that class. Typically, we only refer to "this" instance when a non-static member function returns a reference to the current instance.


Why static functions cannot use instant variables?

Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.


What facility static gives in class?

Static variables or function provides global view to the application that is u can access a static variable with one or more than one objects of a single class without loosing i.e. reinitializing its value.


Why toplevel class cannot be static?

A toplevel class certainly can be static. Static has nothing to do with the level of a class.