Re: Future of C++
On Aug 12, 9:09 am, Andrei Alexandrescu
<SeeWebsiteForEm...@erdani.org> wrote:
Andre Kaufmann wrote:
Aren't stack allocated objects which use virtual functions a minority ?
I don't know for sure.
They are, and probably few if any would shed a tear if they were
disallowed entirely.
Huh? Consider this (adapted from the real code)
//3rd party lib
class Customization
{
//other stuff...
virtual void do_stuff() = 0;
//other stuff...
};
class Algorithm
{
//other stuff..
void Preform(Customization & customization)
{
customization.do_stuff();
}
//other stuff...
};
//User application
class MyCustomization : public Customization
{
//other stuff...
virtual void do_stuff();
//other stuff...
};
int foo(Algorithm & alg)
{
MyCustomization customization;
alg.Perform(customization);
};
Do you really want to force everybody to allocate MyCustomization on
heap[1]? You can of course avoid virtual functions here using generic
programming but:
a) template approach cannot be used in every scenario (consider that
the interfaces above may be exposed by other binary components -
something C++ templates cannot do well)
b) the fact that other approaches exist doesn't make classic OO bad or
invalid
c) you don't control what paradigm is used by 3rd party libs
So, sorry, but I at least will shed a giant tear if this construct was
disallowed. ;-)
[1] - Java does just that and it causes big problems with running out
of memory when creating many such small objects.
--
Eugene
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]