Old problem with performance

Weed resume755 at mail.ru
Mon Feb 23 07:46:11 PST 2009


naryl пишет:

>>>>>> --bb
>>>>> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=83506
>>>> You should use a struct there!   Your code does not show you doing
>>>> anything that would even remotely suggest using a class is worthwhile.
>>>>  You're doing value operations on value types.  That's what structs
>>>> are for.
>>>  	
>>> Why?
>>>
>>> What if I have not substantiated the fact that c1 is a class I should
>>> use there a structure?
>>>
>>> Used in D a model of placement classes only in heap have a rule "if you
>>> made the class and trying to pass it by value is somewhere in your code,
>>> there is a design error?
>> Explains why the question is given in this form:
>>
>> I am received or wrote a classes. Is it right to overload the operator
>> opAdd and use them? I think yes.
>>
>> But why not allow this operation at the same speed that allows C++?
> 
> If you pass it by value you'll lose polymorphism.

Debatable

By the way, in my example the transfer class by value is not
important(!), it is important to create a temporary class on the stack.
Then we can pass a reference without problem (C++ allows this through
the "&")

> That must mean that you inherit that class only to avoid duplicating code. And that is easily done with template mixins.

It is possible that this polymorphism is not needed and should be
prohibited for operations by value. The class is ready, why it should
not be used and have to redo it?

Can not think about changing when the class is ready - he could have
enormous complexity and hierarchy.



More information about the Digitalmars-d mailing list