Hiding class pointers -- was it a good idea?
eao197
eao197 at intervale.ru
Thu Aug 16 01:47:40 PDT 2007
On Thu, 16 Aug 2007 12:28:07 +0400, Bill Baxter
<dnewsgroup at billbaxter.com> wrote:
>>> 3) Value types just don't work for polymorphic behavior. They must be
>>> by reference. There's no way in C++ to ensure that your class
>>> instances are used properly by reference only (hence (2)). In fact, in
>>> C++, it's *extra work* to use them properly.
>> But from another side all types in C++ (internal or user defined) is a
>> first class citizens. It is especially important in generic
>> programming, where I can write:
>> template< class T >
>> class ValueHolder {
>> T * m_value
>> public :
>> ValueHolder() : m_value( new T() ) {}
>> ...
>> };
>> and this code will work as with int, as with std::string, as with
>> ValueHolder<SomeAnotherType>.
>
> I hear you. Fortunately it's pretty trivial to throw some
> static-if-is-zzle at the problem in D. May not be so pretty, but it's
> straightforward at least.
I suppose that the problem becomes more complex in the case when template
class has some methods which receive or return objects by reference or by
value. In C++ it is straightforward, but in D it is required some
static-if-metaprogramming.
--
Regards,
Yauheni Akhotnikau
More information about the Digitalmars-d
mailing list