Page 1 of 1

Programming .NET framework

Posted: Sat Jul 12, 2014 3:55 pm
by icealys
1.I was looking at a windows form application and i came across this. this->textBox1 = (gcnew System::Windows::Forms::TextBox());. I understand that gcnew is sort of the same as new and delete but gcnew is for auto garbage collection for CLR. In the c++ programming tutorials I have only come across a format like this : pointer = new classname. What does it mean when you add a function name at the end ? In this case (gcnew System::Windows::Forms::TextBox()) textbox() is the function at the end. I was talking to someone about creating new objects and they told me that each new object gets a copy of the member variables. for example: when calling the constructor in a class, the constructor allocates new memory for each variable and assigns each one a value.


2. Also, I came across this. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {} when i created a button. This is the actual event handler that was created for the button. What does private: mean at the beginning? I have never seen this before. Is that like an optional command to explicity tell the compiler that it is a private function?

Re: programming .net framework

Posted: Sat Jul 12, 2014 6:04 pm
by AndrewAPrice
Hi iceayls. It looks like you're using C++/CLI. Both of those questions are just c++ questions and not specific to the .Net framework.

1) That function is actually the constructor. When you call new/gcnew to create an object it first allocates memory for it and then calls the constructor, which is a special function, to initialize the object (setting default member variables and what not).

2) Yes, private makes that function 'private' to the object - code in other classes won't be able to access it directly by name.