Hiding class pointers -- was it a good idea?
Bill Baxter
dnewsgroup at billbaxter.com
Thu Aug 16 01:28:07 PDT 2007
eao197 wrote:
> On Thu, 16 Aug 2007 01:35:17 +0400, Walter Bright
> <newshound1 at digitalmars.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.
--bb
More information about the Digitalmars-d
mailing list