du****@mit.edu (Keith H Duggar) wrote in message news:<b4*************************@posting.google.c om>...
I think this feature could save us a lot of headache.
Would this really save that much? I don't see what it saves other than
writing one line in each function, i.e. :
class Funky{
public : doStuff() {
// dostuff
}
} ;
class MoreFunky: public Funky{
public: void doStuff(){
Funky::dostuff() ;
// do more stuff
}
};
class AdvancedFunky: public MoreFunky{
public: void doStuff(){
MoreFunky::dostuff() ;
// do advanced stuff
}
} ;
This achieves the behavior you want quite easily without a language
extension and without virtual functions. Moreover, it allows you to
control the order of the functions calls. Suppose you want to have
them executed in order :
AdvancedFunky::doStuff()
MoreFunky::doStuff()
Funky::doStuff()
then just change the code to :
class MoreFunky: public Funky{
public: void doStuff(){
// do more stuff
Funky::dostuff() ;
}
};
class AdvancedFunky: public MoreFunky{
public: void doStuff(){
// do advanced stuff
MoreFunky::dostuff() ;
}
} ;
Or any other mix you prefer. How would this be accomplished with "auto
virtual"? Would be need another keyword such as "reverse auto virtual"
or "retro virtual"?
:) Well, maybe the choice of "auto" is a bit stupid ( I just took
first kw that came to my mind). More appropriate would be
"constructorlike" :)
Would this really save that much? I don't see what it saves other than
writing one line in each function, i.e. :
class Funky{
public : doStuff() {
// dostuff
}
} ;
class MoreFunky: public Funky{
public: void doStuff(){
Funky::dostuff() ;
// do more stuff
}
};
class AdvancedFunky: public MoreFunky{
public: void doStuff(){
MoreFunky::dostuff() ;
// do advanced stuff
}
} ;
This achieves the behavior you want quite easily without a language
extension and without virtual functions.
Yes. It is nice in this trivial case. But I don't *want* this kind of
behavior. What I want is constructor-like behavior. Consider this:
class Funky{
public: void doStuff(){
// do stuff
}
};
class MoreFunky: virtual public Funky{
public: void doStuff(){
Funky::doStuff();
// do more stuff
}
};
class AdvancedFunky: virtual public Funky{
public: void doStuff(){
Funky::doStuff();
// do advanced stuff
}
};
class SuperFunky: public AdvancedFunky, public MoreFunky{
public: void doStuff(){
MoreFunky::doStuff();
AdvancedFunky::doStuff();
// do super stuff
}
};
Now it becomes messy because Funky::doStuff() is called twice. And it
gets worse as we multiple-inherit further - more and more
Funky::doStuff()'s are called.
I made a little mistake putting focus on *virtual member functions*.
The issue here is *multiple/virtual inheritance*.
When we multiple inherit, the virtual inheritance mechanism eliminates
duplicate calls to base class constructors. Why not allow this kind of
behavior to ordinary functions (of course if we want to)?
The constructor call logic is pretty straightforward - each
constructor participates in initialisation of it's own piece of final
object. And it happens automatically, the compiler takes care of this.
Is's not hard to imagine the member function could act the same way -
changing it's piece of object down the inheritance chain( skiping the
duplicate base-calls in case of virtual inheritance).
The best solution to this problem ( at least to my humble knowledge )
is something like this:
class Funky{
public: void doStuff(){
doMyStuff();
}
protected: void doMyStuff(){
// do stuff
}
};
class MoreFunky: virtual public Funky{
public: void doStuff(){
Funky::doMyStuff();
doMyStuff();
}
protected: void doMyStuff(){
// do more stuff
}
};
class AdvancedFunky: virtual public Funky{
public: void doStuff(){
Funky::doMyStuff();
doMyStuff();
}
protected: void doMyStuff(){
// do advanced stuff
}
};
class SuperFunky: public AdvancedFunky, public MoreFunky{
public: void doStuff(){
Funky::doMyStuff();
MoreFunky::doMyStuff();
AdvancedFunky::doMyStuff();
doMyStuff();
}
protected: void doMyStuff(){
// do super stuff
}
};
This is pretty ugly as we now have to manage parasite doStuff() member
which does nothing except bunch of calls to doMyStuff()'s. The list of
calls gets biger as we inherit more. Imagine what class would look
like if we'd have dozens of members like this. On top of that, we must
have knowlege of whole inheritance tree if we're up to deriving the
new class.
Instead, I would like to have:
class Funky{
public: constuctorlike void doStuff(){
// do stuff
}
};
class MoreFunky: virtual public Funky{
public: void doStuff(){
// do more stuff
};
class AdvancedFunky: virtual public Funky{
public: void doStuff(){
// do advanced stuff
}
};
class SuperFunky: public AdvancedFunky, public MoreFunky{
public: void doStuff(){
// do super stuff
}
};
The similarity with virtual member is that you define behavior of the
function in base class and it continues to behave that way in all
derived classes. That's what I meant by *auto virtual*. If that
function is at the same time virtual, one would declare it like:
auto virtual virtual void doStuff();
//or better:
constructorlike virtual void doStuff();
//or some fancy new keyword
:)
well, I'm probably talking total bs