总结“内联”的影响? [英] Sum up the effects of "inline"?

查看:74
本文介绍了总结“内联”的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



内联的最初目的该代码是否可以扩展到
的地方。当然,它有其他用途...


首先,以下两个翻译单元将成功编译成一个程序中的



/ * source1.cpp * /


inline int Func(double arg)

{

静态双d = 0。


返回d + = arg;

}


int main ()

{

Func(24.333);

}

/ * source2.cpp * /


inline int Func(double arg)

{

静态双d = 0。


返回d + = arg;

}

这里,内联减轻了我们遵守一个定义规则的需要。


我有两个问题:


(1)什么是放置外部的效果或静态的或静态的

内联函数之前?内联函数是否具有内部联系,外部

链接,或者两者都没有?


(2)模板函数似乎也减轻了我们遵守的需要/>
一个定义规则。这是真的?将

" inline"," extern"或静态的或静态的在模板功能之前?

-


Frederick Gotham

解决方案

>这里,内联减轻了我们遵守一个定义规则的需要。


不,becoz身体被替换为好像没有功能。

(1)放置extern会产生什么影响?或静态的或静态的
内联函数之前?内联函数是否具有内部链接,外部链接或两者都没有?


阅读C ++ - 常见问题解答。

(2)模板功能似乎也减轻了我们遵守
一个定义规则的需要。 。这是真的?


NO,模板函数在实例化时为你提供不同的功能。

将内置内联,外部的效果怎么办? ;或静态的或静态的在模板函数之前?




编译错误


Chandu发布:
< blockquote class =post_quotes>

这里,inline减轻了我们遵守一个定义
规则的需要。



不,becoz身体被替换为好像没有功能。



闭嘴。

(1)放置extern会产生什么影响?或者静态
在内联函数之前?内联函数是否具有内部链接,外部链接,或者两者都没有?





闭嘴。

(2)模板功能似乎也减轻了我们遵守的需要
一个定义规则" ;.这是真的吗?



不,模板函数在实例化时给你不同的功能。



闭嘴。


" inline"," extern"或静态的或静态的在模板函数之前?



编译错误



闭嘴。


四个错误答案,每个回答的声音都比

最后一样。


我认为这是我第一次使用killfile。


-


Frederick Gotham




Frederick Gotham写道:

闭嘴。


哇,提醒我永远不会帮助你。

四个错误的答案,每个答案都比
最后一个更具权威性。


实际上,一个答案是可疑的,一个是不正确的,一个是

是正确的,还有一个没有回答任何问题的建议。 />
我认为这是我第一次使用killfile。




你很顺利。



The original purpose of "inline" was that code could be "expanded in
place". Of course, it has other uses...

For one thing, the following two translation units will compile together
succesfully into a program:

/* source1.cpp */

inline int Func(double arg)
{
static double d = 0.;

return d += arg;
}

int main()
{
Func( 24.333);
}
/* source2.cpp */

inline int Func(double arg)
{
static double d = 0.;

return d += arg;
}
Here, "inline" alleviates our need to abide by the "One Definition Rule".

I have two questions though:

(1) What would be the effect of putting "extern" or "static" before
an inline function? Do inline functions have internal linkage, external
linkage, or neither?

(2) Template functions too seem to alleviate our need to abide by the
"One Definition Rule". Is this true? What would be the effect of putting
"inline", "extern" or "static" before a template function?
--

Frederick Gotham

解决方案

> Here, "inline" alleviates our need to abide by the "One Definition Rule".

No, becoz the body gets substituted as if there is no function.

(1) What would be the effect of putting "extern" or "static" before
an inline function? Do inline functions have internal linkage, external
linkage, or neither?
Read C++-FAQs.
(2) Template functions too seem to alleviate our need to abide by the
"One Definition Rule". Is this true?
NO, template functions gives u different functions upon instantiations.
What would be the effect of putting
"inline", "extern" or "static" before a template function?



compiler error


Chandu posted:

Here, "inline" alleviates our need to abide by the "One Definition
Rule".



No, becoz the body gets substituted as if there is no function.


Shut up.

(1) What would be the effect of putting "extern" or "static"
before
an inline function? Do inline functions have internal linkage,
external linkage, or neither?



Read C++-FAQs.


Shut up.

(2) Template functions too seem to alleviate our need to abide by
the
"One Definition Rule". Is this true?



NO, template functions gives u different functions upon
instantiations.


Shut up.

What would be the effect of putting
"inline", "extern" or "static" before a template function?



compiler error


Shut up.

Four wrong answers, each answered with a more authoritive tone than the
last.

I think this is my first time using a killfile.

--

Frederick Gotham



Frederick Gotham wrote:

Shut up.
Wow, remind me never to help you.

Four wrong answers, each answered with a more authoritive tone than the
last.
Actually, one answer that is dubious, one that is incorrect, one that
is correct, and a suggestion that did not answer any question.

I think this is my first time using a killfile.



You''re well on your way.


这篇关于总结“内联”的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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