An inline function is one that is expanded in line when called. When an inline function is called, its entire code is inserted or substituted at the point of inline function call. At compile time, the C++ compiler performs this substitution. If the inline function is small, it may increase efficiency.
inline return-type function-name(parameters)
{
// function code
}
#include <iostream>
using namespace std;
inline int Min(int x, int y) {//inline function
return (x < y)? x : y;
}
// Main function for the program
int main() {
cout << "Min (20,10): " << Min(20,10) << endl;
cout << "Min (0,200): " << Min(0,200) << endl;
cout << "Min (100,1010): " << Min(100,1010) << endl;
return 0;
}
Min (20,10): 10
Min (0,200): 0
Min (100,1010): 100
Forward declaration is the pre-declaration of the syntax or signature of an identifier, variable, function, class, or other object prior to its use.
#include <iostream>
using namespace std;
// Forward declaration
class A;
class B;
class B {
int x;
public:
void getdata(int n)
{
x = n;
}
friend int multi(A, B);
};
class A {
int y;
public:
void getdata(int m)
{
y = m;
}
friend int multi(A, B);
};
int multi(A m, B n)
{
int result;
result = m.y * n.x;
return result;
}
int main()
{
B b;
A a;
a.getdata(5);
b.getdata(4);
cout << "The Multilication is : " << multi(a, b);
return 0;
}
The Multilication is : 20
Note: also read about Types of Class Member Functions in C++
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…