#define PP_CAT(a,b) a##b
#define PP_CAT_(a,b) a##b
#define PP_STR(s) PP_STR_(s)
#define PP_STR_(s) #s
class CNamedTreePropertyBase
{
public:
CNamedTreePropertyBase() : name(0), pParent_(0) {}
CNamedTreePropertyBase(const TCHAR * const Name,
CNamedTreePropertyBase *pParent) : name(Name)
, pParent_(pParent) {}
const TCHAR *const name;
virtual const TCHAR const *GetName() const = 0;
CNamedTreePropertyBase *pParent_;
};
#define NAMED_PROP(Type, Var, InitialVal, pParentProp) \
class PP_CAT(tag, Var) : public CNamedTreePropertyBase \
{ \
public: \
const TCHAR * const name; \
Type value; \
PP_CAT(tag, Var) () : name(PP_STR(Var)) \
, value(InitialVal) \
, CNamedTreePropertyBase(name, pParentProp) {} \
const TCHAR const *GetName() const {return name;} \
} Var; \
//endmacro
struct A
{
NAMED_PROP(std::string, prop, _T("some value"), 0);
NAMED_PROP(std::string, child_prop, _T("some value"), &prop);
};
Сообщение компилятора:
error C2440: 'reinterpret_cast' : cannot convert from 'class A::tagprop A::*' to 'class CNamedTreePropertyBase *'
There is no context in which this conversion is possible
Какие могут быть причины не преобразовывать указатель на объект класса A в указатель на объект класса B? Это стандартное поведение?