Checking the Existence of a C++ Class Member at Compile Time

TL;DR

  1. Download has_member.hpp
  2. Define a “checker” for a member_name member
    define_has_member(member_name);
    
  3. Use has_member() to check if class_name has a member called member_name
    if (has_member(class_name, member_name))
    {
        // ...
    }
    
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s