Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top