相关疑难解决方法(0)

C++模板和内联

当我编写一个简单的(非模板)类时,如果函数实现是"正确"提供的,它会自动被视为inline.

class A {
   void InlinedFunction() { int a = 0; }
   // ^^^^ the same as 'inline void InlinedFunction'
}
Run Code Online (Sandbox Code Playgroud)

在谈论基于模板的类时,这条规则怎么样?

template <typename T> class B {
   void DontKnowFunction() { T a = 0; }
   // Will this function be treated as inline when the compiler
   // instantiates the template?
};
Run Code Online (Sandbox Code Playgroud)

此外,该inline规则如何应用于非嵌套模板函数,例如

template <typename T> void B::DontKnowFunction() { T a = 0; }

template <typename T> inline void B::DontKnowFunction() { T a = 0; } …
Run Code Online (Sandbox Code Playgroud)

c++ templates inline-method

37
推荐指数
2
解决办法
3万
查看次数

标签 统计

c++ ×1

inline-method ×1

templates ×1