string merge

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carmen Sei

    string merge

    why the following code not compile

    =============== =
    #include <iostream>
    using std::cout; // must need for using cout
    using std::endl;

    #include <string>
    using std::string;

    int main()
    {
    string stringa("abc");
    string stringb("bbb");
    cout << merge (stringa, stringb);


    } // end main

    string merge ( string a, string b){
    string c = a + b;
    return c;
    }
  • Sharad

    #2
    Re: string merge


    "Carmen Sei" <fatwallet951@y ahoo.comwrote in message why the following
    code not compile
    >
    =============== =
    #include <iostream>
    using std::cout; // must need for using cout
    using std::endl;
    >
    #include <string>
    using std::string;
    >
    int main()
    {
    string stringa("abc");
    string stringb("bbb");
    cout << merge (stringa, stringb);
    >
    >
    } // end main
    >
    string merge ( string a, string b){
    string c = a + b;
    return c;
    }
    Compiler needs to know the signature/prototype of the functions that it
    comes across while compiling. We generally include header files for this
    purpose, like <stdio.hfor printf. In your case compiler doesn't know about
    the merge function, when it encounters it in main. So add the function
    prototype of merge before main, or move the definition before main.

    Sharad


    Comment

    • Ron Natalie

      #3
      Re: string merge

      Sharad wrote:
      >
      Compiler needs to know the signature/prototype of the functions that it
      comes across while compiling.
      In C++ the word you are looking for is "declaratio n".
      Prototype is a C term.

      Signature is something else.

      Comment

      Working...