什么时候应该使用-inl.h文件? [英] When should I use -inl.h files?

查看:176
本文介绍了什么时候应该使用-inl.h文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚记下了 Google C ++编码样式指南中的此项-我不太了解

I just noted this item in the Google C++ Coding Style Guide - and I don't quite get it.

如果我将内联方法或函数放在其他文件所包含的标头之外的文件中,则它将不是该类的方法;并且仅适用于包含它的代码位.那么,为什么还要甚至拥有这样的-inl.h文件呢?

If I put an inline method or function in a file other than the header included by other files, it will not be a method of the class; and it will only be usable to bits of code which include it. So why even have such -inl.h files at all?

此外,为什么我们仍然要内联长函数? (即,除了模板以外,当我们必须将代码放在头文件中进行实例化时)

Also, why do we even want to inline long functions anyways? (i.e. other than in the case of templates, when we have to put the code in the header files for instantiation)

推荐答案

通常对长函数模板执行此操作.常规头文件my_functions.h仅包含声明,而实现文件my_functions-inl.h包含实现.原因是不能将功能模板放在.cpp 文件中.请注意,X.h文件包含X-inl.h文件,而不是相反.

This is often done for long function templates. The regular header my_functions.h only contains the declarations, and the implementation file my_functions-inl.h contain the implementations. The reason is that function templates cannot be put in .cpp files. Note that the X.h file includes the X-inl.h file, not the other way around.

其他库具有不同的命名约定:一些Boost库使用.hpp作为模板头,使用.ipp作为模板实现文件.

Other libraries have different naming conventions: e.g. some of the Boost libraries use .hpp for template headers and .ipp for template implementation files.

这篇关于什么时候应该使用-inl.h文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆