A
Alex
Hi. I'll try my problem with this example:
class C {
protected:
virtual int* getProtected(int index)=0;
public:
const int* get(int index) const
{ return (const int*) getProtected(index); }
virtual void set(int index, int value)
{ *getProtected(index) = value; }
...
};
class D : public C {
protected:
int* getProtected(int index) { ... }
};
I need a way to set a value and get a const pointer to that thing. I
want the base class to provide a standard way for set, which is just
copy the value. My approach is to make it easy: the child classes only
would need to implement getProtected and get() and set() will work ok.
If that class needs to do some extra processing when set() is called,
it can implement it, but otherwise it will work ok. getProtected is
protected to prevent to get a non-const pointer outside the class.
I don't know if you can understand me. Anyway, my problem is that that
doesn't work, because getProtected is a const member function and get()
is const.
Can you help me?
Thanks!!
class C {
protected:
virtual int* getProtected(int index)=0;
public:
const int* get(int index) const
{ return (const int*) getProtected(index); }
virtual void set(int index, int value)
{ *getProtected(index) = value; }
...
};
class D : public C {
protected:
int* getProtected(int index) { ... }
};
I need a way to set a value and get a const pointer to that thing. I
want the base class to provide a standard way for set, which is just
copy the value. My approach is to make it easy: the child classes only
would need to implement getProtected and get() and set() will work ok.
If that class needs to do some extra processing when set() is called,
it can implement it, but otherwise it will work ok. getProtected is
protected to prevent to get a non-const pointer outside the class.
I don't know if you can understand me. Anyway, my problem is that that
doesn't work, because getProtected is a const member function and get()
is const.
Can you help me?
Thanks!!