• Welcome to Valhalla Legends Archive.
 

[C++] Inline member functions

Started by NeBuR, February 09, 2004, 08:54 AM

Previous topic - Next topic

NeBuR

In the book "Industrial Strength C++" (by Mats Henricson and Erik Nyquist, Prentice Hall PTR, 1997, ISBN 0-13-120965-5), which I recommended some weeks ago in the "C++ tutorial & reference websites" thread, it's recommended the next three-file structure for separate class declaration (in a header file) and inline member function implementation:

a) Header file
// MyClass.h
// MyClass header file.

// ...
// Myclass declaration ...
// ...

// Always include at the end:
#ifndef DISABLE_INLINE
#include "MyClass.inl"
#endif


b) Non-inline member function implementation
// MyClass.cpp
// MyClass non-inline member function implementation file.

#include "MyClass.h"

// ...
// Non-Inline member function implementation...
// ...

// Always include at the end:
#ifdef DISABLE_INLINE
#include "MyClass.inl"
#endif


c) Inline member function implementation
// MyClass.inl
// MyClass inline member function implementation file.

// #include statements (don't include "MyClass.h").

// Do not include anything after this point.
#ifdef DISABLE_INLINE
#define inline
#endif

// ...
// Inline member function implementation...
// ...

#ifdef DISABLE_INLINE
#undef inline
#endif


The original considered different file extensions for both header (.hh), non-inline member function implementation (.cc) and inline function implementation (.icc), but this no matters at all.

This class file model recommends not to declare as inline any function inside class declaration, but do it directly in funcion implementation (which, if inline, should be included in the .inl file).

I've tried this class file structure, and i like it, because it's good to hide inline member function bodies (not present in header file) and inlining itself (not present at class declaration in header file). Now, I'd like to know your opinion about this file structure, as well as any other convention you use in order to organized the code. Thanks :)