i dont know about "using namespace std". I have never used . Can you please elaborate?
and i also dont know about inline functions, i got the inline function error many times but never understand what really it is?
A namespace is where variables are declared for later use , std is a namespace in which cout and cin are declared as objects of ostream and istream classes (respectively).
Without writing "using namespace std" before main , cout,cin,endl and any other thing declared in std is not available to the program so it gives 'cout/cin undeclared' error.
An alternative to writing "using namespace std" (and the preferred way) is by using the scope resolution operator ::
So you should use std::cout instead of cout and std::cin instead of cin (same for every name that is declared in std ).
As for inline functions it is a little difficult to explain but I'll try .
What happens when you call a function(mind I am using call here , not define) in the code ?
example
void myfunction(void){std::cout<<"hey";} //function definition
int main(){
myfunction(); //function called
}
When you execute the program and the execution reaches the line where myfunction is called , it looks for the function's definition Now this process takes a little time , as execution jumps from the line where myfunction was called to the line where it is defined .
Making an function 'inline' means that the execution will not have to jump from here to there looking for function but instead the compiler copies and pastes the function definition everywhere the function is called(before turning it into the .exe) .
so
inline void myfunction(void){std::cout<<"hey";}
int main(){
myfunction();//called here
}
this time the execution won't jump from the line where it is called to the line where it is defined instead it will do this
int main(){
void myfunction(void){std::cout<<"hey";}
myfuntion();//called here
}
So you see ? Its like it pastes the function definition everywhere the function is called , the program might run a bit faster since it will not have to jump from here to there BUT you are trading speed with space. It is obvious that it will take more space since it has more lines of code . Therefore,only functions which are 3-4 lines long are to be made inline .Imagine a function of hundred linepasted everywhere in the code , it will make the code lengthy and thus take more space.
There are two ways to make a function inline ,
*either by the use of the keyword inline before its prototype(or definition if you don't give the prototype separately)
*or by giving the function definition inside(instead of defining the function outside of class declaration e.g: void class_name::myfunction(); ) the class declaration (This doesn't require mentioning the keyword inline before prototype) .