How to use Inline function in C++

1 Answer

0 votes
#include <iostream>
#include <string>

inline void print(std::string s) { 
    std::cout << s << "\n";
}

int main()
{
    // whenever you call the function print() the compiler 
    // will replace the function call with the code from the function
    
    print("C++ Programming"); 
    print("C++ inline function"); 
    print("Code"); 
}
 
 
 
/*
run:
 
C++ Programming
C++ inline function
Code

*/

 



answered Dec 19, 2024 by avibootz
...