INL File Introduction
The Inl file is the source file for the inline function. Inline functions are usually implemented in a C + + header file, but when there are too many inline functions in the C + + header file, we want to make the header file look concise, and can you put inline function declarations and function definitions in the header and implementation files like normal functions? The answer is yes, of course, by placing the implementation of the inline function in the Inl file and then using the Inl file at the end of the header file #include
.
Because the compiler does not support the template functions, template classes and so on separate compilation, but with the Inl file, we can put the declaration in the header file, and then put the implementation in the Inl file.
For larger projects, for administrative reasons, the declarations of template functions, template classes are typically placed in one or a few header files, and then the definitions are partially placed in the Inl file. This allows the engineering structure to be clear and straightforward.
The Inl file is also mentioned in Google's C + + code programming specification, where students who need to read can read Google's C + + code specification: Google C + + Style guide.
Simple example
//inl_demo.h
#ifndef _INL_DEMO_H_
#define _INL_DEMO_H_
template<typename T>
T return_max(T &T1, T &T2);
#include "inl_demo.inl"
#endif
//inl_demo.inl
#ifndef _INL_DEMO_INL_
#define _INL_DEMO_INL_
#include "inl_demo.h"
template<typename T>
treturn_max ( t & T1, t Span class= "o" >&t2) {
return T1 > T2 ? T1 : T2;
}
#endif
//main.cc
#include <iostream>
#include "inl_demo.h"
using namespace std;
intmain ( argc char *< span class= "n" >argv[]) {
int a = 10;
int b = 20;
cout << "The Max is:" << span class= "n" >return_max ( a, b< Span class= "p" >) << endl
return 0;
}
Hahaya
Source: Http://hahaya.github.com/inline-file-in-cplusplus
This article is copyrighted by the author, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link.
INL in C + +