template specialization for static member functions; howto?

后端 未结 5 774
情歌与酒
情歌与酒 2021-02-05 19:03

I am trying to implement a template function with handles void differently using template specialization.

The following code gives me an \"Explicit specialization in non

5条回答
  •  感情败类
    2021-02-05 19:43

    It's not directly an answer to your question but you can write this

    template 
    static T safeGuiCall(boost::function _f)
    {
            if (_f.empty())
                    throw GuiException("Function pointer empty");
            {
                    ThreadGuard g;
                    return _f();
            }
    }
    

    It should work even if _f() return 'void'

    Edit : In a more general case, I think we should prefer function overloading instead of specialization. Here is a good explanation for this : http://www.gotw.ca/publications/mill17.htm

提交回复
热议问题