简体   繁体   中英

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 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM