Valhalla Legends Forums Archive | C/C++ Programming | [C++] Inline member functions

AuthorMessageTime
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
[code]// MyClass.h
// MyClass header file.

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

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

b) Non-inline member function implementation
[code]// 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
[/code]

c) Inline member function implementation
[code]// 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
[/code]

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 :)
February 9, 2004, 2:54 PM

Search