假设我们不想提示编译器在适用的情况下内联成员函数。
class Base
{
public:
inline virtual f() = 0;
};
class Derived : public Base
{
public:
virtual f() override; // no inline specifier here
};
我是否需要在 Derived::f()
中指定 inline
或者我可以省略关键字并确保 virtual Derived::f()
与 inline Derived::f()
相同吗?
我的意思是 inline
关键字是为 Derived::f()
隐式指定的,还是我需要再次显式键入它?
最佳答案
Do I need to specify
inline
inDerived::f()
or can I omit the keyword and be sure thatvirtual Derived::f()
is the same thing asinline Derived::f()
?
如果在派生类中省略inline
关键字,则它在派生类中就不是inline
。
I mean is the
inline
keyword implicitly specified forDerived::f()
不,不是。
or do I need to explicitly type it once again?
是的,你知道。但是,编译器很可能会为它生成代码,就好像它是非内联
成员函数一样,因为它是虚拟
成员函数。
关于c++ - inline 关键字在哪里指定、基类、派生类还是两者都重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369540/