I have a class which is derived off a class provided in a third party library.
Between versions of the third party library, they promoted a member in one of their classes from private to public, but in the move, they deprecated a method for accessing the member. Example:
// Old class
class A
{
public:
int &GetA() { return a;}
private:
int a;
};
// NewClass
class A
{
public:
int a;
};
My code uses an instance of A
, but I want my code to work with either version, in case someone hasn't updated the library.
class B
{
public:
int & ReturnA() { return GetInnards(m_a);}
private:
A m_a;
// If m_a has a GetA member function call this:
template(typename aType)
int & GetInnards(aType &a) { return a.GetA(); }
// If m_a does not have an GetA() member function, call this:
template(typename aType)
int & GetInnards(aType &a) { return a.m_a; }
};
It seems like I should be able to use SFINAE, but I'm missing something.
Also, there is nothing I can test with an #ifdef
, so I can't go that route. I need to detect if a method exists, and or if a member is public.