After migrating from MS Visual Studio 2008 to MS Visual Studio 2017 and compiling using v140 toolset, I got a problem with defining whether a specific member variable is present in class. In my case it not a simple variable but a static const reference. It worked fine in under 2008.
Here is an extract from my code which doesn't compile
#include <iostream>
#include <string>
struct ActivityEntry
{
static const std::string& AutoIncrementName;
};
template< typename Entry >
struct AutoIncrementNameSelect
{
template< const std::string* >
struct TestHasMember;
template< typename T >
static int f( TestHasMember< &T::AutoIncrementName >*, void* );
template< typename T >
static char f( TestHasMember< &T::AutoIncrementName >*, ... );
enum { UseAutoIncrement = ( sizeof( f< Entry >( 0, 0 ) ) == sizeof( int ) ) };
};
std::string s("aaa");
//initialize the reference
const std::string & ActivityEntry::AutoIncrementName(s);
int main()
{
std::cout<<"Use autoinc:"<< AutoIncrementNameSelect<ActivityEntry>::UseAutoIncrement;
return 0;
}
In my original code the error is: "pointer to reference member is illegal" with reference to:
enum { UseAutoIncrement = ( sizeof( f< Entry >( 0, 0 ) ) == sizeof( int ) ) };
Here, the error is
error: '& ActivityEntry::AutoIncrementName' is not a valid template argument for 'const string* {aka const std::basic_string*}' because it is not the address of a variable