分类: C/C++
2017-08-08 18:33:30
class module_good
{
public:
const char* get_name(){}
};
class module_bad
{
};
struct has_get_name
{
template<typename T, const char* (T::*)()>
struct func_matcher;
public:
template<typename T>
static bool test(func_matcher*)
{
return true;
}
template<typename T>
static bool test(...)
{
return false;
}
};
void test3()
{
bool b_ret = false;
b_ret = has_get_name::test(NULL);
b_ret = has_get_name::test(NULL);
}
template<typename T>
struct has_get_name2
{
typedef char true_t[1];
typedef char false_t[2];
template<typename T2, const char* (T::*)()>
struct func_matcher;
template<typename T2>
static true_t& test(func_matcher*);
template<typename T2>
static false_t& test(...);
enum
{
result = (sizeof(test(NULL)) == sizeof(true_t))
};
};
void test4()
{
bool b_ret = false;
b_ret = has_get_name2::result;
b_ret = has_get_name2::result;
}