What's the relationship between C++ template and duck typing?

后端 未结 7 1966
一向
一向 2020-12-29 17:48

To me, C++ template used the idea of duck typing, is this right? Does it mean all generic types referenced in template class or method are duck type?

7条回答
  •  有刺的猬
    2020-12-29 18:29

    Yes, sort of - for example if type X has AddRef(), Release() and QueryInterface() methods with appropriate signatures it can be used as a COM object with CComPtr template class. But this is not complete duck typing - type checking is still enforced for parameters.

提交回复
热议问题