Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

Is "inline" implicit in C++ member functions defined in class definition

According to the C++ specification, are the following two classes equivalently defined?

class A
{
   void f()
   {
   }
};

class B
{
   inline void f()
   {
   }
};

i.e., is putting the "inline" qualifier on such member function defined in the class definition completely redundant?

Followon question: Assuming it is redundant, for code style, would it be sensible to keep the "inline" tag, so a future developer realises that function should be inlined, and does not remove the definition somewhere else and remove the inlining?

Thanks :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The C++ ISO standard says:

A function defined within a class definition is an inline function.

But, this doesn't mean the function will necessarily be inlined: generally nowadays, it appears that the compiler will decide if inlining the function will lead to any benefits.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...