Restrict C++ Template Parameter to Subclass

前端 未结 7 1590
醉话见心
醉话见心 2020-11-28 22:04

How can I force a template parameter T to be a subclass of a specific class Baseclass? Something like this:

template 

        
7条回答
  •  情深已故
    2020-11-28 22:31

    You could use Boost Concept Check's BOOST_CONCEPT_REQUIRES:

    #include 
    #include 
    
    template 
    BOOST_CONCEPT_REQUIRES(
        ((boost::Convertible)),
    (void)) function()
    {
        //...
    }
    

提交回复
热议问题