INL in C + +

Source: Internet
Author: User

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
  1. //inl_demo.h
  2. #ifndef _INL_DEMO_H_
  3. #define _INL_DEMO_H_
  4. template<typename T>
  5. T return_max(T &T1, T &T2);
  6. #include "inl_demo.inl"
  7. #endif
  1. //inl_demo.inl
  2. #ifndef _INL_DEMO_INL_
  3. #define _INL_DEMO_INL_
  4. #include "inl_demo.h"
  5. template<typename T>
  6. treturn_max ( t & T1, t Span class= "o" >&t2) {
  7. return T1 > T2 ? T1 : T2;
  8. }
  9. #endif
  1. //main.cc
  2. #include <iostream>
  3. #include "inl_demo.h"
  4. using namespace std;
  5. intmain ( argc char *< span class= "n" >argv[]) {
  6. int a = 10;
  7. int b = 20;
  8. cout << "The Max is:" << span class= "n" >return_max ( a, b< Span class= "p" >) << endl
  9. return 0;
  10. }
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 + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.