头文件:
#include
模板类别:
template
struct is_member_function_pointer;
句法:
std::is_member_function_pointer::value
参数:模板std :: is_member_function_pointer接受单个参数T(Trait类),以检查T是否是指向非静态成员函数的指针。
返回值:该模板std :: is_member_object_pointer返回一个布尔变量,如下所示:
- True:如果类型T是指向非静态成员函数类型的指针。
- False:如果类型T不是指向非静态成员函数类型的指针。
下面是演示C++中std :: is_member_function_pointer的程序:
程序1:
// C++ program to illustrate
// std::is_member_function_pointer
#include
#include
using namespace std;
// Declare a structure
class GFG {
public:
int gfg;
};
class A {
};
// Driver Code
int main()
{
// Object to class GFG
int GFG::*pt = &GFG::gfg;
cout << boolalpha;
// Check if GFG* is a member function
// pointer or not
cout << "GFG*: "
<< is_member_function_pointer::value
<< endl;
// Check if int GFG::* is a member
// function pointer or not
cout << "int GFG::* "
<< is_member_function_pointer::value
<< endl;
// Check if int A::* is a member
// function pointer or not
cout << "int A::* "
<< is_member_function_pointer::value
<< endl;
// Check if int A::*() is a member
// function pointer or not
cout << "int A::*() "
<< is_member_function_pointer::value
<< endl;
return 0;
}
输出:
GFG*: false
int GFG::* false
int A::* false
int A::*() true
程式2:
// C++ program to illustrate
// std::is_member_function_pointer
#include
#include
using namespace std;
// Declare a structure
struct A {
void fn(){};
};
struct B {
int x;
};
// Driver Code
int main()
{
void (A::*pt)() = &A::fn;
cout << boolalpha;
cout << "A*: "
<< is_member_function_pointer::value
<< endl;
cout << "void(A::*)(): "
<< is_member_function_pointer::value
<< endl;
cout << "B*: "
<< is_member_function_pointer::value
<< endl;
cout << "void(B::*)(): "
<< is_member_function_pointer::value
<< endl;
return 0;
}
输出:
A*: false
void(A::*)(): true
B*: false
void(B::*)(): true
参考: http : //www.cplusplus.com/reference/type_traits/is_member_function_pointer/
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。