Question: So, I heard that C++ templates shouldn't be separated into a header (.h) and source (.cpp) files.

For instance, a template like this:

```
template <class T>
class J
{   
   T something;
};

```

Is this true? Why is it so?

If because of that I'm gonna have to put both declaration and implementation in the same file, should I put it in a .h file or a .cpp file?

Answer: 
The reason you can't put a templated class into a .cpp file is because in order to "compile" a .cpp file you need to know what the type that is being used in place of T. As it stands a templated class (like your class J) doesn't have enough information to compile. Thus it must be all in headers. 

If you want the break up the implementation into another file for cleanliness, the best practice is to use an .hxx file. Like this: inside your header file, J.h, put:

```
#ifndef _J_H__
#define _J_H__

template <class T> class J{  // member definitions };

#include "j.hxx"

#endif // _J_H__

```

and then, in j.hxx you'll have 

```
template <class T> J<T>::J() { // constructor implementation }

template <class T> J<T>::~J() { // destructor implementation }

template <class T> void J<T>::memberFunc() { // memberFunc implementation }

// etc.

```

Finally in your .cpp file that uses the templated class, let's call it K.cpp you'll have:

```
#include "J.h" // note that this always automatically includes J.hxx    
void f(void)
{
     J<double> jinstance;  // now the compiler knows what the exact type is.
}

```
Yes, it's true. Declaration and implementation are generally put into the header file all together. Some compilers experimented with an `export` keyword that would allow them to be separated, but that has been removed from C++0x. Check out [this FAQ entry](http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12) for all the dirty details.