Skip to content
Related Articles

Related Articles

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:




// C++ program to illustrate
// std::is_member_object_pointer
#include <bits/stdc++.h>
#include <type_traits>
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 object
    // pointer or not
    cout << "GFG*: "
         << is_member_object_pointer<GFG*>::value
         << endl;
  
    // Check if int GFG::* is a member
    // object pointer or not
    cout << "int GFG::*  "
         << is_member_object_pointer<int GFG::*>::value
         << endl;
  
    // Check if int A::* is a member
    // object pointer or not
    cout << "int A::*  "
         << is_member_object_pointer<int A::*>::value
         << endl;
  
    // Check if int A::*() is a member
    // object pointer or not
    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/

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :