class - C++/CLI: " Button^ button1; " what is ^ meaning here? -
this question has answer here:
- what caret (‘^’) mean in c++/cli? 7 answers
i created windowsform class in c++/cli 1 button , onclick event. looked source code , saw this:
public ref class myform : public system::windows::forms::form { public: myform(void) { initializecomponent(); // //todo: add constructor code here // } protected: /// <summary> /// clean resources being used. /// </summary> ~myform() { if (components) { delete components; } } private: system::windows::forms::button^ button1; ... private: system::void onclickbutton1(system::object^ sender, system::eventargs^ e) { } }
i ask: meaning of ^
operator when declaring button (button^ button1;
) in class?
the handle declarator (^, pronounced "hat"), modifies type specifier mean declared object should automatically deleted when system determines object no longer accessible.
so button^
declares pointer garbage-collected button
object, allocated using gcnew
instead of new
:
the ref new aggregate keyword allocates instance of type garbage collected when object becomes inaccessible, , returns handle (^) allocated object.
Comments
Post a Comment