views:

69

answers:

2

I have a class Helper:

template <typename T, template <typename> E>
class Helper {
    ...
};

I have another class template, Exposure, which is to inherit from Helper while passing itself as the template template parameter E. I also need to specialize Exposure. Thus I want to write something like the following:

template <>
class Exposure<int> : public Helper<int, Exposure> {
    Exposure() : Helper<int, Exposure>() {
        ...
    };
    ...
};

Unfortunately this won't compile. gcc complains:

Exposure.h:170: error: type/value mismatch at argument 2 in template parameter list for `‘template > class ExposureHelper’

Exposure.h:170: error: expected a constant of type ‘’, got ‘Exposure’

Am I doing something wrong? Is there a workaround for what I'm trying to do?

A: 

In your first template for Helper, you don't need to say the second parameter is a template:

template <typename T, typename E>
class Helper {
    ...
};

And you can declare one with a template as an argument:

Helper<vector<int>, vector<char> > h;

But in your second template, you have a circular definition. Your Exposure class depends on your Exposure class. This creates a circular reference, and the Helper class needs the definition of Exposure before you can inherit from Exposure. You may need to restructure your classes.

JoshD
+1  A: 

if you really want to pass template rather then class

template <typename T, template<typename> class E>
class Helper {
};

template <typename T>
class Exposure;

template <>
class Exposure<int> : public Helper<int, Exposure > {
};

or if your intent is different

template <typename T, typename E>
class Helper {
};

template <typename T>
class Exposure;

template <>
class Exposure<int> : public Helper<int, Exposure<int> > {
};
aaa