Significance of a .inl file in C++

后端 未结 5 1205
旧时难觅i
旧时难觅i 2020-12-02 05:22

What are the advantages of having declarations in a .inl file? When would I need to use the same?

5条回答
  •  鱼传尺愫
    2020-12-02 05:49

    .inl files are never mandatory and have no special significance to the compiler. It's just a way of structuring your code that provides a hint to the humans that might read it.

    I use .inl files in two cases:

    • For definitions of inline functions.
    • For definitions of function templates.

    In both cases, I put the declarations of the functions in a header file, which is included by other files, then I #include the .inl file at the bottom of the header file.

    I like it because it separates the interface from the implementation and makes the header file a little easier to read. If you care about the implementation details, you can open the .inl file and read it. If you don't, you don't have to.

提交回复
热议问题