c++ cli - Why doesn't .NET CLI provide synthesized copy constructors and assignment operators for reference classes? -
i writing simple gui using visual c++ in .net framework , curious why there no synthesized re-create constructors or assignment operators reference classes?
basically, started windows form application in visual studio , have own info construction of parameters. but, need instances of (and pointers instances of it) in mainform class , since latter reference class had create struct reference too.
so long , short of because c++cli .net language, reference based language (garbage collected, 2 indistinguishable in case). default reference, meaning instances accessed via handles, in
foo^ = gcnew foo(); foo^ b = a;
a
, b
point same object. true other reference-defualting languages java.
the side effect of is, unlike c++, nobody "owns" instance pointed a
. actual lifetime of longer handles. makes making default re-create constuctor impossible. take simple reference class:
ref class foo { bar^ bar; };
when create re-create of foo, compiler has no way of knowing if foo owns bar or not. thus, cannot decide whether or not re-create handle (shallow copy) or instantiate new bar
(deep copy). thus, designers of such language don't typically provide default re-create constructor.
.net c++-cli copy-constructor assignment-operator
No comments:
Post a Comment