Template << and >> operators specialization

我与影子孤独终老i 提交于 2019-12-06 15:12:48

You don't need to specialize the operator template: just write an overload taking a std::string:

class sql_command {
    /* ... */

    template<typename T>
    sql_command& operator>>(const T& arg) { 
        /* general purpose implementation */ 
    }

    sql_command& operator>>(const std::string& arg) { 
        /* special std::string implementation */ 
    }
};

Function template specialization is yucky and should be avoided wherever possible. For more information, consult Herb Sutter's Why Not Specialize Function Templates?

You forgot to use class resolution operator ::

template<>
inline sql_command& sql_command::operator>> <std::string> (const std::string& arg)
                      see this ^^ 

Do this for other specialization also!

Or better follow James advice!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!