我已阅读以下问题:
我明白什么C++ functors
是好的。但是我无法推断如果执行以下操作会发生什么:
template <typename T, unsigned int state>
class Foo {
public:
static Foo_func() { /* Do something */ };
}
// Partial specialization:
// -- state == 1
template <typename T>
class Foo <T, 1> {
public:
static Foo_func() { /* Do something */ };
}
template <typename F>
void call_func(F func) {
// Do something... //
func();
// Do something... //
}
int main() {
Foo <double, /*state*/ 1> obj;
// Case 1:
call_func(obj.Foo_func);
// Case 2:
call_func(Foo<double, /*state*/ 1>::Foo_func);
}
Run Code Online (Sandbox Code Playgroud)
在哪种情况下编译器将能够内联Foo_func()
?
但是我无法推断如果执行以下操作会发生什么
不可能推断出会发生什么,你只需要尝试看看。
内联是一种优化,而不是一种语言特性。它何时以及是否发生取决于您的编译器、它的版本、您如何配置它,以及(可能是内联的)调用站点周围的许多其他上下文。
归档时间: |
|
查看次数: |
240 次 |
最近记录: |