Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I declare a function ?

How do I declare a function ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questioncsharpjava
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    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); } }; }

    R P 2 Replies Last reply
    0
    • A Anonymous

      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); } }; }

      R Offline
      R Offline
      Randhir Sinha
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Anonymous

        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); } }; }

        P Offline
        P Offline
        PremL
        wrote on last edited by
        #3

        As an accomplished Java programmer you should consider C# as an option. You would have a much easier time learning it than managed C++. But everything depends on what you want to do. Lorenz Prem Microsoft Corporation

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups