std::is_member_object_pointer template in C++ with Examples
Last Updated :
12 Jun, 2020
The std::is_member_object_pointer template of C++ STL is present in the <type_traits> header file. The std::is_member_object_pointer template of C++ STL is used to check whether the T is a pointer to non-static data member object or not. It return the boolean value true if T is a pointer to non-static data member object type, otherwise it return false.
Header File:
#include<type_traits>
Template Class:
template< class T >
struct is_member_object_pointer
Syntax:
std::is_member_function_pointer<T>::value
Parameter: The template std::is_member_object_pointer accepts a single parameter T(Trait class) to check whether T is a pointer to non-static data member object type or not.
Return Value: This template std::is_member_object_pointer returns a boolean variable as shown below:
- True: If the type T is a pointer to non-static data member object type.
- False: If the type T is not a pointer to non-static data member object type.
Below is the program to demonstrate std::is_member_object_pointer: in C++:
Program:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
class GFG {
public :
int gfg;
};
class A {
};
int main()
{
int GFG::*pt = &GFG::gfg;
cout << boolalpha;
cout << "GFG*: "
<< is_member_object_pointer<GFG*>::value
<< endl;
cout << "int GFG::* "
<< is_member_object_pointer< int GFG::*>::value
<< endl;
cout << "int A::* "
<< is_member_object_pointer< int A::*>::value
<< endl;
cout << "int A::*() "
<< is_member_object_pointer< int (A::*)()>::value
<< endl;
return 0;
}
|
Output:
GFG*: false
int GFG::* true
int A::* true
int A::*() false
Reference: http://www.cplusplus.com/reference/type_traits/is_member_object_pointer/
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...