简体   繁体   English

在C ++中使用内联构造函数和析构函数

[英]Usage of Inline for constructors and Destructors in C++

I am new to C++.I was told not to use Inline with Constructors(containing user defined datatypes as arguments) and destructors. 我是C ++的新手。我被告知不要使用Inline with Constructors(包含用户定义的数据类型作为参数)和析构函数。

Is there any such thing in C++? C ++中有没有这样的东西?

I think it is fine to use Inline for constructors and destructors as long as they are short and simple(not complicated). 我认为只要它们简短(不复杂)就可以使用Inline作为构造函数和析构函数。

Can someone help me out.An example would help.Thanks. 有人可以帮帮我。一个例子会有所帮助。谢谢。

There is no rules like that. 没有这样的规则。 inline is nothing more than a hint to the compiler and it can do whatever it wants on it. inline只不过是对编译器的一个提示,它可以做任何想做的事情。

Note that methods define in the class declaration are implicitly inline, and modern compiler support link time optimisation to allow inlining cross multiple compilation unit… 请注意,类声明中定义的方法是隐式内联的,而现代编译器支持链接时优化,以允许内联交叉多个编译单元...

So give the hint on what you think is right like short functions or constructors and trust your compiler to do what is best, it will be right at 99.9% 所以给出你认为正确的短函数或构造函数的提示,并相信你的编译器做最好的事情,它将是99.9%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM