#pragma once
#include <type_traits>
#include <iostream>
template <typename _Tp>
struct __is_member_pointer_helper
: public std::false_type
{
};
template <typename _Tp, typename _Cp>
struct __is_member_pointer_helper<_Tp _Cp::*>
: public std::true_type
{
};
class MyClass
{
public:
int nTmp = 1.1;
float fTmp = 2.2;
};
void TestIsMember()
{
auto p1 = &MyClass::nTmp;
float MyClass::* p2 = &MyClass::fTmp;
MyClass c1;
std::cout << c1.*p1 << std::endl;
std::cout << c1.*p2 << std::endl;
std::cout << __is_member_pointer_helper<decltype(p1)>::value << std::endl; // 输出 true
std::cout << __is_member_pointer_helper<float MyClass::*>::value << std::endl; // 输出 true
}
类成员 指针
最新推荐文章于 2024-08-04 22:43:03 发布