class - C++/CLI: " Button^ button1; " what is ^ meaning here? -


this question has answer here:

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?

^ handle object operator:

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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -