Methods in C++
When we declare any function within a class its called method.There are two types of methods in C++:-
- Inline Method
- Outline Method
Inline Method
When we declare and describe any function within a class its called inline method
Example:-
#include<iostream.h>
#include<conio.h>
class aptech
{
public:
display()
{
cout<<"inline method";
}
};
void main()
{
aptech ap;
clrscr();
ap.display();
getch();
}
#include<conio.h>
class aptech
{
public:
display()
{
cout<<"inline method";
}
};
void main()
{
aptech ap;
clrscr();
ap.display();
getch();
}
Outline method
when we declare any function within a class but describe outside of the class is called outline method.
Example:-
#include<iostream.h>
#include<conio.h>
class aptech
{
public:
display();
};
aptech::display()
{
cout<<"outline method";
}
void main()
{
aptech ap;
clrscr();
ap.display();
getch();
}
Inline Keyword
When we want to call any function(method) within a class without object then we will use inline keyword.inline keyword always works with outline method.
Example:-
#include<iostream.h>
#include<conio.h>
class aptech
{
public:
inline display();
};
inline display()
{
cout<<"inline keyword";
}
class aptech
{
clrscr();
display();
getch();
}
#include<conio.h>
class aptech
{
public:
inline display();
};
inline display()
{
cout<<"inline keyword";
}
class aptech
{
clrscr();
display();
getch();
}