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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…