Assigning object instances on the managed heap appears to be using Managed Extensions C + +, C #, J #, VB. NET programmer, and programmers who use local C + + can not only allocate memory on the heap, but are even more accustomed to using a stack based object instance.
Now review the previously defined point reference class, and then look at the following variable definitions:
Point p1, p2(3,4);
From the point of view of local C + +, p1 and P2 should be based on the stack reference class point instance, even from a general standpoint. The P1 is initialized by the default constructor, and P2 is initialized by the constructor that accepts the x and Y coordinates. From an implementation standpoint, point is a self-contained type (i.e., it does not contain any pointers or handles), however, as an instance of a reference class, it is still under the control of the CLI runtime and, if necessary, is garbage-collected-because of this, it is not possible to define a static or global instance of a reference class.
Meanwhile, you also cannot apply sizeof to an expression that indicates that it is referencing a class instance because the sizeof is evaluated at compile time, and the point object is sized until run time, but the sizeof can be applied to a handle because its size is determined at compile time.
Also, you cannot define a stack-based CLI array instance.
Trace References
Local C + + can use & to define an object's alias, for example, for any local class N, you can write the following code:
N n1;
N& n2 = n1;
References must be initialized at definition time, and throughout life, they are locked in reference to the same object, that is, its value does not change. An instance referencing a reference class is basically consistent with referencing a local class, except that the syntax is different.
Instances of reference classes are "moved" in memory during program execution, so they need to be tracked while local pointers and references are not qualified for this work (especially if you cannot use the address character & for an instance of a reference class), so c++/ The CLI provides a handle and a reference for tracing--this is referred to as a trace reference (tracking References), for example, you can define a trace reference P3 to track the object P2: