Including an Inline File - C++ Preprocessor

C++ examples for Preprocessor:Directive

Introduction

Create an .inl file and #include it at the end of your header file.

This is equivalent to putting the function definition at the end of the header file.

// Value.h
#ifndef VALUE_H__
#define VALUE_H__

#include <string>

class Value {
public:
   Value (const std::string& val) : val_(val) {}
   std::string getVal() const;
private:
   std::string val_;

};

#include "Value.inl"

#endif VALUE_H__

// Value.inl
inline std::string Value::getVal() const {
   return(val_);
}

Related Tutorials