c++ - inline 关键字在哪里指定、基类、派生类还是两者都重要吗?

标签 c++ inheritance inline virtual

假设我们不想提示编译器在适用的情况下内联成员函数。

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 in Derived::f() or can I omit the keyword and be sure that virtual Derived::f() is the same thing as inline Derived::f() ?

如果在派生类中省略inline关键字,则它在派生类中就不是inline

I mean is the inline keyword implicitly specified for Derived::f()

不,不是。

or do I need to explicitly type it once again?

是的,你知道。但是,编译器很可能会为它生成代码,就好像它是非内联成员函数一样,因为它是虚拟成员函数。

关于c++ - inline 关键字在哪里指定、基类、派生类还是两者都重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369540/

相关文章:

javascript - JavaScript 中的继承 : child object still calling its parent method

Scala:有没有办法创建内联类型?

f# - 适用于所有数值数据类型的函数

android - 原生Android VS2015无法打开源文件

c++ - "and"什么时候成为 C++ 中的运算符

c++ - 可以为间接基类共享基类实例吗?

java - 为什么从构造函数调用 Set 方法不是一个好主意?

c++ - C++ 中未命名命名空间的使用

c++ - OpenCV/C++:warpPerspective产生过度扭曲的结果

python - 如何在 python 2.7 中使用内联 if else 语句打印单行