template specialization for static member functions; howto?

后端 未结 5 789
情歌与酒
情歌与酒 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:46

    Your problem appears to be with boost::function - the following specialisations work:

    template 
    T safeGuiCall()
    {
        return T();
    }
    
    template <>
    void safeGuiCall()
    {
    }
    
    int main() {
        int x = safeGuiCall();     // ok
        //int z = safeGuiCall();  // this should & does fail
        safeGuiCall();            // ok
    }
    

提交回复
热议问题