Checking whether a template argument has a member function [duplicate]

只愿长相守 提交于 2019-12-01 08:59:52
Pawel Zubrycki

Little modification of MSalters' idea from Is it possible to write a C++ template to check for a functions existence? :

template<typename T>
class has_member_func
{
        typedef char no;
        typedef char yes[2];
        template<class C> static yes& test(char (*)[sizeof(&C::member_func)]);
        template<class C> static no& test(...);
public:
        enum{value = sizeof(test<T>(0)) == sizeof(yes&)};
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!