In C++, what is the use of template parameter when it doesn't appear in the following class or function declaration?

Viewed 42

Many times I see these types of codes.
What is the use of template in the code below?
I ask this because the template parameter T does not appear in the declaration.

template <typename T>
struct op_pointer_to_mat;
template <typename T>
struct op_pointer_to_col_vect;

Does it mean that the definition of op_poineter_to_mat and op_pointer_to_col_vect is somewhere else with template parameter T?

1 Answers

This is called a forward declaration. The class must be declared fully somewhere later. Could be the same file or a different header. It just lets the compiler know that the name Test is valid and the blanks will be filled in later.

template<typename Type>
class Test;

template<typename Type>
class Test
{
public:
    Type valueFor() { }
};
Related