P
Patrick Kowalzick
Hello all,
I have a templated class. This class is a parent class of quite some classes
spread over a projects. As changes inside member-function definitions force
a recompile of many files, I search a way around the lack of the
export-functionality.
I started to seperate the declaration and definition:
*** template_class_declaration.h ***
template <class T>
class A
{
public:
void foo();
};
*** file end ***
*** template_class.h ***
#include "template_class_declaration.h"
template <class T>
void A<T>::foo()
{
doSomething();
}
*** file end ***
Like this I can still use
#include "template_class.h"
like before.
For somehow "known-types" (by the implementor) I added another file for
explicit instantiation:
*** template_instantiation.cpp ***
#include "template_class.h"
#include "all_neccessary_includes.h"
template class A<SomeOtherClass>;
*** file end ***
For files using these explicit instanciated classes, I can change the
include directive from
#include "template_class.h"
to
#include "template_class_declaration.h"
Like this I do not need complete recompilation for changes in the
definition. For my first small tests this works fine.
What do you think about this structure? Did I overlook something? What do
you do in these cases?
Kind regards,
Patrick
I have a templated class. This class is a parent class of quite some classes
spread over a projects. As changes inside member-function definitions force
a recompile of many files, I search a way around the lack of the
export-functionality.
I started to seperate the declaration and definition:
*** template_class_declaration.h ***
template <class T>
class A
{
public:
void foo();
};
*** file end ***
*** template_class.h ***
#include "template_class_declaration.h"
template <class T>
void A<T>::foo()
{
doSomething();
}
*** file end ***
Like this I can still use
#include "template_class.h"
like before.
For somehow "known-types" (by the implementor) I added another file for
explicit instantiation:
*** template_instantiation.cpp ***
#include "template_class.h"
#include "all_neccessary_includes.h"
template class A<SomeOtherClass>;
*** file end ***
For files using these explicit instanciated classes, I can change the
include directive from
#include "template_class.h"
to
#include "template_class_declaration.h"
Like this I do not need complete recompilation for changes in the
definition. For my first small tests this works fine.
What do you think about this structure? Did I overlook something? What do
you do in these cases?
Kind regards,
Patrick