سؤال

We don't need to declare inline functions explicitly since their implementations are defined in a header file. But for organization purpose, I want to do it. For example

// Group declaration firstly for readability.
inline void fooA();
inline void fooB();
inline void fooC();
...

// Implementations
inline void fooA()
{
   ...
}

inline void fooB()
{
   ...
}

inline void fooC()
{
   ...
}

My question is: may I need both inline keywords in declaration and implementation or one of them can be deleted?

I found an answer there Forward declaration of inline functions . So this is a repeated question. Sorry about that.

هل كانت مفيدة؟

المحلول

You need to include it in either the declaration, the definition, or both.

But note that the definition must be visible in every compilation unit that uses the function.

نصائح أخرى

You don't need both. You can delete inline keyword in implementation and keep inline keyword when you declare functions... It is same as virtual keyword

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top