2012-04-28 39 views

回答

4

你可以使用tag分派

template <typename T> class xyz 
{ 
    public: 
    void foo() 
    { 
    foo(typename boost::is_base_of<bar,T>::type()); 
    } 

    protected: 
    void foo(boost::mpl::true_ const&) 
    { 
    // Something 
    } 

    void foo(boost::mpl::false_ const&) 
    { 
    // Some other thing 
    } 
}; 

注意标签调度通常比使用enable_if SFINAE更好,因为enable_if需要的线性数选择合适的载之前模板实例。

在C++ 11,可以使用的std ::这些相当于提振元功能。