I have some software in C++ which uses both regular and template functions, and I wish to organize my directories properly. To implement this, I followed the guidelines of this stack question and wrote header files (.hpp), files with regular functions (.cpp) and files with template functions (.tpp). However, my current directory is poorly organized, like so
/
-include/
-src/
--foo.cpp
--foo.hpp
--foo.tpp
--bar.cpp
--bar.hpp
--bar.tpp
--mysoft.cpp
--mysoft.hpp
-Makefile
-mysoft.o
where mysoft.hpp is my main file which contains #include "foo.cpp"
and #include "bar.cpp"
.
I have a two questions regarding the improvement of this implementation:
How would I organize my software tree if I wanted to move files to an include/ folder and not have them all in src/? Should I put both .hpp and .tpp files in include/, or keep the .tpp files in src/?
How do I deal with the #include calls between source, header and template files if some files are in inc/?
Here are examples of typical files foo.cpp
, foo.hpp
and foo.tpp
.
// foo.cpp
#ifndef FOO_CPP
#define FOO_CPP
#include <somelibrary>
#include "foo.hpp"
void foo_f() {
// some function
}
// foo.hpp
#ifndef FOO_HPP
#define FOO_HPP
void foo_f();
template<class T> class fooclass {
private:
int var;
public:
void foo_g();
}
#include "foo.tpp"
// foo.tpp
#ifndef FOO_TPP
#define FOO_TPP
template<class T>
void fooclass<T>::foo_g() {
// some other function
}