move object from heap to stack
Ali Çehreli
acehreli at yahoo.com
Thu Sep 20 08:47:41 PDT 2012
On 09/20/2012 03:37 AM, monarch_dodra wrote:
> On Thursday, 20 September 2012 at 10:20:24 UTC, Johannes Pfau wrote:
>> http://dlang.org/struct.html
>> D classes do not really have copy constructors. You could assume that
>> if a constructor has only one argument and it's of the same type as
>> the class, it's a copy constructor.
>
> True... the term "copy constructor" is not 100% accurate, it is just "a
> constructor that takes the same type"
>
> A a = new A(); //Creates a new A
> A b = a; //Binds to the existing A
> A c = new A(a); //Constructs a new A, form an old A.
A polymorphic member function would be better for when A is just a base
class, i.e. when we don't know its actual type (the virtual constructor
idiom):
void foo(Animal a)
{
Animal c = a.dup; // can be any Animal
// ...
}
Ali
More information about the Digitalmars-d-learn
mailing list