Class:
A user defined datatype that compromises member variable and member functions is known as class. They might be public, private or protected.
class class_name
{
private:
member variables;
member variables;
public:
member variables;
member variables;
};
Object:
An instance of class is called object.
ABC a;
class object
Inline function:
One of the object of function is to save memory space. Everytime a function is called it takes a lot extra time in executing a series of instructions for tasks such as jumping to the function, saving register, pushing argument into stack and returning to the calling function. When a function is small, a substantial function is small, a substantial percentage of execution time may be spent in such overheads.
C++ has a solution to this problem, which is inline function. An inline function is a function that is expanded in line when it is invoked i.e. compiler replaces the function call with the corresponding function code.
inline function header
{
function body;
}
Example:
inline int cube(int m)
{
return(m*m*m);
}
Inline function sends a request, not a command to the compiler. The compiler may ignore this request if the function definition is too long or too complicated and compile the function as normal function.
Situations where inline function may not mark as:
#include<iostream.h>
inline int square(int a)
{
return(a*a)
}
void main()
{
int m=5, n;
n=square(m);
cout<<"square of number given="<<n;
}
Function overloading:
void sum (int a, int b)
void sum( int a, floatb)
void sum(int a, int b, int c)
Function overriding
void sum(int a, int b)
void sum(int a, int b)
A user defined datatype that compromises member variable and member functions is known as class. They might be public, private or protected.
class class_name
{
private:
member variables;
member variables;
public:
member variables;
member variables;
};
Object:
An instance of class is called object.
ABC a;
class object
Inline function:
One of the object of function is to save memory space. Everytime a function is called it takes a lot extra time in executing a series of instructions for tasks such as jumping to the function, saving register, pushing argument into stack and returning to the calling function. When a function is small, a substantial function is small, a substantial percentage of execution time may be spent in such overheads.
C++ has a solution to this problem, which is inline function. An inline function is a function that is expanded in line when it is invoked i.e. compiler replaces the function call with the corresponding function code.
inline function header
{
function body;
}
Example:
inline int cube(int m)
{
return(m*m*m);
}
Inline function sends a request, not a command to the compiler. The compiler may ignore this request if the function definition is too long or too complicated and compile the function as normal function.
Situations where inline function may not mark as:
- For function returning values, if a loop ; switch or goto eists.
- If the function contains static variables.
- If inline functions are recursive.
#include<iostream.h>
inline int square(int a)
{
return(a*a)
}
void main()
{
int m=5, n;
n=square(m);
cout<<"square of number given="<<n;
}
Function overloading:
void sum (int a, int b)
void sum( int a, floatb)
void sum(int a, int b, int c)
Function overriding
void sum(int a, int b)
void sum(int a, int b)
No comments:
Post a Comment