• Create Account

### #ActualNercury

Posted 08 April 2013 - 09:16 AM

The approach I use is this (seems like "Method 3"):

// template_file.h

#pragma once

/* YOUR TEMPLATE DECLARATION HERE */

#include <template_file.inline.h>


And definitions:

// template_file.inline.h

#pragma once
#include <template_file.h>

/* DEFINITIONS HERE */


"inline" file is used like a usual .cpp file. This speeds up compilation a lot.
Sadly, I don't remember where I first found this approach.

Edit: you can replace "pragma once" with "#ifndef .., #define ..". Same thing.

Ok, so you have two header files?

Having a hard time visualizing your approach. The way I understand it is this:
- template-file.hpp: this is where you have the class declaration (and the sub-methods)
- template-file.inline.hpp: this is a just a place-holder file to make it easier for the compiler to swallow
- template-file.cpp: this is where the implementation of the template class is located

Am I right or am I way off?

No, implementation is in template-file.inline.hpp, because there is no .cpp file. Template files are inlined anyways per-use. Or, should I say, compiler chooses how and where to compile multiple binaries resulting from used variations of the template parameters.

You would include template-file.hpp in other files to use template.

### #1Nercury

Posted 08 April 2013 - 09:15 AM

The approach I use is this (seems like "Method 3"):

// template_file.h

#pragma once

/* YOUR TEMPLATE DECLARATION HERE */

#include <template_file.inline.h>


And definitions:

// template_file.inline.h

#pragma once
#include <template_file.h>

/* DEFINITIONS HERE */


"inline" file is used like a usual .cpp file. This speeds up compilation a lot.
Sadly, I don't remember where I first found this approach.

Edit: you can replace "pragma once" with "#ifndef .., #define ..". Same thing.

Ok, so you have two header files?

Having a hard time visualizing your approach. The way I understand it is this:
- template-file.hpp: this is where you have the class declaration (and the sub-methods)
- template-file.inline.hpp: this is a just a place-holder file to make it easier for the compiler to swallow
- template-file.cpp: this is where the implementation of the template class is located

Am I right or am I way off?

No, implementation is in template-file.inline.hpp, because there is no .cpp file. Template files are inlined anyways per-use.

You would include template-file.hpp in other files to use template.

PARTNERS