Search code examples
c++11inline

Why there is still a inline specifier when member fuctions define inside class?


The C++ ISO standard says: A function defined within a class definition is an inline function.

But look at the code as follows: leveldb-skiplist

class template <typename Key, class Comparator>
class SkipList{
 public:
  /*
   ...
  */
 private:
  inline int GetMaxHeight() const {
    return max_height_.load(std::memory_order_relaxed);
  }
};

there is still an explicit inline specifier when GetMaxHeight is defined inside class.

So, I want to know why we still need an explicit inline when a function defined within a class?


Solution

  • You don't need it. It's redundant. Just like repeating virtual in the declaration of an override.

    The grammar allows it, because it's a function definition, and there's no additional wording that bans it.