Re: to_derived virtual member function
They can't. But they don't need to. Your problem was the declaration in
the base class. The solution has been pointed out at least twice now;
briefly it is:
derived *base::to_derived() { return 0; }
derived *derived::to_derived() { return this; }
No dynamic_cast needed.
Yes, it works in the sense that it returns a pointer to derived, not a
polymorphic pointer to base (which was intended in the first place). I
wonder why it doesn't appear as a standard procedure.
Am I missing something?
Yes.
What would that be? Can you show me one of your peer-reviewed journal
papers where this matter is discussed? Or maybe a large-scale
application?
Well, despite your inadequate tone I will write this: when I first
started seeing NSValue in ObjC, it made little sense for C++. Then I
realized that, despite the apparent syntax burden, it would save
maintenance time since there is no ad-hoc writing of value insertion
and extraction operators (<< and >>) and classes become mostly
different (in terms of stored values) in their constructors AND access
functions.
For example, using basicvalue, it would read like:
class usevalue
{
public:
usevalue(dag* graph)
{
data=new Vector("Properties");
data.push(new Integer("A property");
....
}
void functionusingdataorgraph(...)
{}
void write(ostream& os)
{
os<<*data;
}
void read(istream& is)
{
is>>*data;
}
private:
basicvalue* data;
};
It is of course a much cleaner approach than using (ad-hoc) value
syntax for contained data. So, what was I missing then?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]