将文件放入.h文件中? [英] Putting implmentation in .h files?

查看:100
本文介绍了将文件放入.h文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




你能否告诉我在.h文件中放置瑕疵

的准则是什么?

我看到他们将getter / setting的实现放在

.h文件中的实例,其中funcitons是> 10行代码放入.cpp

文件。


这是指南吗?


谢谢。

Hi,

Can you please tell me what is the guideline in Putting implmentation
in .h files?
I see examples where they put the implementation of getter/setting in
the .h files where funcitons is > 10 lines of code are put in .cpp
file.

Is that the guideline?

Thank you.

推荐答案

你好!


我看到两个案例,你把它放在哪里在.h文件中实现:

1.当你有一个模板类并且你不想搞乱pImpl

的东西。

2.如果你真的很小并经常打电话给你,那么你将把b $ b放入一个舱位宣言中。请考虑每个

函数是否为decl。类是自动内联的。


class foo

{

public:

int bar (); //在其他地方声明

void haha​​()//这是自动内联

{

//一些小代码

}

};

Hello!

I see two cases as to where you put the implementation in .h file:
1. When you have a template class and you don''t want to mess with pImpl
stuff.
2. When you have really small and calling very often functions that you
will put into a declaration of class. Please, consider that every
function that is in decl. of class is automaticallly an inline.

class foo
{
public:
int bar(); //declared somewhere else
void haha() //this is automatically inline
{
//some small code
}
};


通常在头文件和实现中进行decleraions

在cpp文件中。但模板应该在

头文件中声明并实现。

Normally the decleraions are made in the header files and implentaions
are in cpp file. But templates should be declared and implement in the
header file itself.


Backer写道:
通常在头文件中进行decleraions,并且实现
在cpp文件中。但模板应该在
头文件中声明并实现。
Normally the decleraions are made in the header files and implentaions
are in cpp file. But templates should be declared and implement in the
header file itself.




....或者你隐藏了模板声明的实现在

a单独的.inl文件中,并在

模板的标题中包含最后一个语句。因此,您可以模拟界面的分离和模板的实现细节 - 我通常更喜欢的方法和

推荐。


问候



.... or you hide away the implementation of a template''s declarations in
a separate .inl file and include it with a last statement in the
template''s header. So, you can emulate separation of interface and
implementation details for templates - an approach I usually prefer and
recommend.

Greets


这篇关于将文件放入.h文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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