How do I declare a function ?
-
I just got Visual C++ .NET tonight and I started messing around with it. I'm a java developer and have been kind of curious of the .NET I'm really stuck i've search google.com but the word .NET brings up alot of junk. I'm stuck on declaring a function not sure how. I keep getting an error (error C3602: 'String': a __gc type object cannot be passed by value) It's right when I pass it to the function that will make the string to uppercase. Not sure what it means a __gc could someone help me out or show me where i can look at some online docs for newbies thanks.
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { this->label1->Text = this->textBox1->Text; this->strBox = this->textBox1->Text; //MessageBox::Show(strBox,S"Text in Box", MessageBoxButtons::OK, MessageBoxIcon::Information); this->upperCase = this->makeUpperCase(strBox); this->daString(upperCase); } public: System::Void daString(System::String * blah) { MessageBox::Show(blah,S"Testing Function daString", MessageBoxButtons::OK, MessageBoxIcon::Information); } String makeUpperCase(System::String * upper) { //upper->ToUpper; return upper->ToUpper(); } private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) { MessageBox::Show(S"Message Box Demo",S"My Application", MessageBoxButtons::OK, MessageBoxIcon::Asterisk); } }; }
-
I just got Visual C++ .NET tonight and I started messing around with it. I'm a java developer and have been kind of curious of the .NET I'm really stuck i've search google.com but the word .NET brings up alot of junk. I'm stuck on declaring a function not sure how. I keep getting an error (error C3602: 'String': a __gc type object cannot be passed by value) It's right when I pass it to the function that will make the string to uppercase. Not sure what it means a __gc could someone help me out or show me where i can look at some online docs for newbies thanks.
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { this->label1->Text = this->textBox1->Text; this->strBox = this->textBox1->Text; //MessageBox::Show(strBox,S"Text in Box", MessageBoxButtons::OK, MessageBoxIcon::Information); this->upperCase = this->makeUpperCase(strBox); this->daString(upperCase); } public: System::Void daString(System::String * blah) { MessageBox::Show(blah,S"Testing Function daString", MessageBoxButtons::OK, MessageBoxIcon::Information); } String makeUpperCase(System::String * upper) { //upper->ToUpper; return upper->ToUpper(); } private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) { MessageBox::Show(S"Message Box Demo",S"My Application", MessageBoxButtons::OK, MessageBoxIcon::Asterisk); } }; }
If you look closely, the String::ToUpper function returns a String*, whereas you are using a String return type. Try String* makeUpperCase( String* inString ) { return inString->ToUpper(); } There are minor differences between C++ and C++ .Net. C++ .Net compiles to MSIL code, and it has introduced the concept of garbage-collectable (__gc) classes. Since System::String is a __gc class, and not a value type like an int, so you can only use pointers to it in your code.
-
I just got Visual C++ .NET tonight and I started messing around with it. I'm a java developer and have been kind of curious of the .NET I'm really stuck i've search google.com but the word .NET brings up alot of junk. I'm stuck on declaring a function not sure how. I keep getting an error (error C3602: 'String': a __gc type object cannot be passed by value) It's right when I pass it to the function that will make the string to uppercase. Not sure what it means a __gc could someone help me out or show me where i can look at some online docs for newbies thanks.
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { this->label1->Text = this->textBox1->Text; this->strBox = this->textBox1->Text; //MessageBox::Show(strBox,S"Text in Box", MessageBoxButtons::OK, MessageBoxIcon::Information); this->upperCase = this->makeUpperCase(strBox); this->daString(upperCase); } public: System::Void daString(System::String * blah) { MessageBox::Show(blah,S"Testing Function daString", MessageBoxButtons::OK, MessageBoxIcon::Information); } String makeUpperCase(System::String * upper) { //upper->ToUpper; return upper->ToUpper(); } private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) { MessageBox::Show(S"Message Box Demo",S"My Application", MessageBoxButtons::OK, MessageBoxIcon::Asterisk); } }; }