简体   繁体   中英

Template Specialization of Template method

OK I have:

template<typename T>
class Reader
{
    class Input
    {
        template<typename C>
        void operator()(C& val) const
        {
            /* Do Some Work */
        }
    };
};

Unfortunately the generic version of "Do Some Work" does not work for me. Nor it is easy to modify because it is in the middle of some heavy template meta programming code.

So I though I could specialize the method for my type. So my first step was to try and pull the general method out of the class.

template<typename T>
class Reader
{
    class Input
    {
        template<typename C>
        void operator()(C& val) const;
    };
};


template<typename T>
template<typename C>
void typename Reader<T>::Input template operator()<C>(C& val) const   // LINE 13
{
    /* Do Some Work */
}

Unfortunately I am getting the error:

sh:13: error: error: expected ')' before '&' token

Just write it like normal

template<typename T>
template<typename C>
void Reader<T>::Input::operator()(C& val) const   // LINE 13
{
    /* Do Some Work */
}

Defining the generic version out of class doesn't help you with providing special versions of it though, or I do miss the goal of yours here.

I guess it is impossible as it counts as partial function template specialization, which is not allowed. void Reader<T>::Input::operator () (C& int) has an implicit first argument (the this pointer) of type Reader<T>::Input * , hence its signature is in fact void (Reader<T>::Input *, C &) . You are trying to specify C , yet not T .

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