this is rather a strange question but I am using nested classes to make property-like functionality in c++.
I also made these work as ReadOnly by making the nested class's assignment operator protected and the host class a Friend
of the nested class.
Unfortunately it seems that any inheriting class (with : public BaseClass
) still cant access the nested class's assignment operator.
I dont know if it matters but I did put the Friend
in the public section of the class.
Anyone know how I can fix this? (or hack it) Thanks
EDIT: code example added
#define ReadOnlyProperty(type,name,parent) \
protected: \
class name : public PropertyBase<type> \
{ \
parent* This; \
public: \
friend class parent; \
name(parent* instance) { This = instance; } \
protected: \
void operator=(type value) {Set(value);} \
void Set(type value); \
type Get() const; \
}; \
public: name name; \
friend class name; \
private:
Base class:
class Object
{
ReadOnlyProperty(char,Type,Object);
public:
Object() : Type(this) {}
};
Inheriting class
class A : public Object
{
public:
A() {Type = 'A';}
};
i get an error on the Type = 'A'