• Create Account

### #Actualkloffy

Posted 08 April 2013 - 09:12 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.

For most purposes, this is probably the best way to go. Only one thing:

#include <template_file.h>

This line in "template_file.inline.h" is redundant, unless you include "template_file.inline.h" from somewhere else and are not sure if "template_file.h" will be included beforehand. Otherwise the include guards just do their job. In my opinion, it is cleaner to just say that the "*.inline.h" files are not for use outside of "*.h".

@ysg: There is no "*.cpp". The "#include" directive basically inserts the plain text from the included file verbatim. From the compilers view, everything ends up inside the header. The inline files containing the implementation are just for organization.

### #4kloffy

Posted 08 April 2013 - 09:11 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.

For most purposes, this is probably the best way to go. Only one thing:

#include <template_file.h>

This line in "template_file.inline.h" is redundant, unless you include "template_file.inline.h" from somewhere else and are not sure if "template_file.h" will be included beforehand. Otherwise the include guards just do their job. In my opinion, it is cleaner to just say that the "*.inline.h" files are not for use outside of "*.h".

@ysg: There is no "*.cpp". The "#include" directive basically inserts the plain text from the included file verbatim. From the compilers view, everything ends up inside the header. The inline files are just for organization.

### #3kloffy

Posted 08 April 2013 - 09:10 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.

For most purposes, this is probably the best way to go. Only one thing:

#include <template_file.h>

This line in "template_file.inline.h" is redundant, unless you include "template_file.inline.h" from somewhere else and are not sure if "template_file.h" will be included beforehand. Otherwise the include guards just do their job. In my opinion, it is cleaner to just say that the "*.inline.h" files are not for use outside of "*.h".

@ysg: Thereis no "*.cpp". The "#include" directive basically inserts the plain text from the included file verbatim. From the compilers view, everything ends up inside the header. The inline files are just for organization.

### #2kloffy

Posted 08 April 2013 - 09:10 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.

For most purposes, this is probably the best way to go. Only one thing:

#include <template_file.h>

This line in "template_file.inline.h" is redundant, unless you include "template_file.inline.h" from somewhere else and are not sure if "template_file.h" will be included beforehand. Otherwise the include guards just do their job. In my opinion, it is cleaner to just say that the "*.inline.h" files are not for use outside of "*.h".

@ysg: Thereis no "*.cpp". The "#include" directive basically inserts the plain text from the included file verbatim. From the compilers view, everything ends up inside the header. The inline files are just for organization.

### #1kloffy

Posted 08 April 2013 - 09:09 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.

For most purposes, this is probably the best way to go. Only one thing:
#include <template_file.h>
This line in "template_file.inline.h" is redundant, unless you include "template_file.inline.h" from somewhere else and are not sure if "template_file.h" will be included beforehand. Otherwise the include guards just do their job. In my opinion, it is cleaner to just say that the "*.inline.h" files are not for use outside of "*.h".

@ysg: Thereis no "*.cpp". The "#include" directive basically inserts the plain text from the included file verbatim. From the compilers view, everything ends up inside the header. The inline files are just for organization.

PARTNERS