class=
data] == class member
methods]
by default all class member are private if we are not use access specifier
Access Specifier(in c++)
1. private
2. protected
3. public
access specifier specify the accessibility of the members
private means we can access only within a class ]protected is same as private till
inheritance
public means we can access inside and outside of the class
class A
{
public:
int a; = a is public
protected
int b;
= b and c both are protected
in c;
}
class A
{
public:
int a; = a and b both are public
int b;
private = c is private
in c;
}
in c++ we always use semicolon at the end of class after the class to teminate
class
in c we use semicolon at the structure
in java and c# not use semicolon at the end of class
procedural
oops is set of rules or concepts or approach to solve the problems
encapsulation means putting class and data in a single unit
class is the implementation of the concept called encapsulation
data almost will be private (not always)
methods almost will be public (not always)
class methods can access class data
class student
{
}
#include<iostream>
using namespace std;
class MPGI
{
//data
public:
int a,b,c;
//methods
public: //Access specifier
void input();
void process();
void output();
};
void MPGI:: input()
{
cout<<"Enter two numbers: ";
cin>>a>>b; //input
}
void MPGI:: process()
{
c=a+b; //process
}
void MPGI:: output()
{
cout<<"Sum= "<<c;
}
int main()
{
MPGI obj;
obj.input();
obj.process();
obj.output();
return 0;
}
normal function
inline function
you can not make every function as inline because inline is the keyword which
request the compiler (it depends the rules follow by the compiler)
inline = function that comes in one and two line
INLINE FUNCTION PROGRAM=
#include<iostream>
using namespace std;
inline int add(int x,int y)
{
int z;
z=x+y;//process
return z;
}
int main()
{
int a,b,c;
cout<<"Enter two numbers -";
cin<<a<<b;//input
c=add(a,b);
cout<<"Sum"
}
function control to the function body
if function is complex then not use inline
if any member method is defined inside the class then it by default inline not need
to use keyword inline
good coder do small function that is one r two line that keeps inside the class and
the function which has line of
code more than one or two then keep it outside of the class
INLINE FUNCTION==
=>whenever a function is called, it takes a lot of extra time in executing
Interview question
what is the differece between inline function and macro function?