How to forward declare a C++ template class?

c++, forward-declaration, templates

Solution

This is how you would do it:

template<typename Type, typename IDType=typename Type::IDType>
class Mappings;

template<typename Type, typename IDType>
class Mappings
{
public:
    ...
    Type valueFor(const IDType& id) { // return value }
    ...
};

Note that the default is in the forward declaration and not in the actual definition.

Problem

Given a template class like the following: ``` template<typename Type, typename IDType=typename Type::IDType> class Mappings { public: ... Type valueFor(const IDType& id) { // return value } ... }; ``` How can someone forward declare this class in a header file?

Original source

Related problems