开发者

Problem with template specialization and template template parameters

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 mis开发者_开发百科match 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?


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> > {
};


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜