Restrict C++ Template Parameter to Subclass

前端 未结 7 1603
醉话见心
醉话见心 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:47

    By calling functions inside your template that exist in the base class.

    If you try and instantiate your template with a type that does not have access to this function, you will receive a compile-time error.

提交回复
热议问题