Old problem with performance

Chad J gamerchad at __spam.is.bad__gmail.com
Sun Feb 8 14:59:46 PST 2009


Walter Bright wrote:
> Derek Parnell wrote:
>> On Sun, 08 Feb 2009 11:13:00 -0800, Walter Bright wrote:
>>
>>
>>> In particular, classes are *meant* to be used as reference types, but
>>> the program is trying to treat them as value types. Virtual functions
>>> are orthogonal to what value types are - a continuing problem C++
>>> programs have is conflating value types with reference types.
>>
>> In D, what is the recommend technique to derive one user-defined value
>> type
>> from another?
> 
> There isn't one. Deriving types only makes sense when expecting
> polymorphic behavior, which is completely orthogonal to the whole idea
> of a value type. A polymorphic type should be a reference type.
> 

So far I am seeing that the slicing problem arises from the ability to
place extra data into derived types.  But what of method inheritance?

It seems that something like this could work:

scope class A
{
	int x, y;
	int foo() { etc... }
}

class B : A
{
	// More data members are now forbidden.
	int foo() { etc... }
	void bar(char[] baz) {...}
}

struct S
{
	// in-place allocation
	scope A qux;
	scope A quux;
}

void main()
{
	S s;
	s.qux = new B;
}



More information about the Digitalmars-d mailing list