In a project I'm working on, I have a fairly large templated class that I've implemented like this:
I have my header file
// MyBigClass.h
#ifndef MYBIGCLASS_H
#define MYBIGCLASS_H
template <typename T>
class MyBigClass {
/* -- snip -- */
};
#include "MyBigClass.cpp"
#include "MyBigClass_iterator.cpp"
#include "MyBigClass_complicatedFunctionality_1.cpp"
#include "MyBigClass_complicatedFunctionality_2.cpp"
#endif
And then all of my implementation files look basically like this:
// MyBigClass_foobar.cpp
template <typename T>
void MyBigClass<T>::member_1(){
/* -- snip -- */
}
template <typename T>
int MyBigClass<T>::member_2(int foo, T & bar){
/* -- snip -- */
}
// etc, etc
In main.cpp
, I just include MyBigClass.h
, and everything works and compiles fine. The reason I've split the implementation into many files is because I prefer working on three or four 200-400 line files, versus one 1200 line file. The files themselves are fairly logically organized, containing for example only the implementation of a nested class, or a group of interrelated member functions.
My question is, is this something that is done? I got a strange reaction when I showed this to someone the other day, so I wanted to know if this is a bad practice, or if there is a better, more usual way to accomplish something like this.