468,513 Members | 1,759 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

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;
}
Apr 3 '08 #1
2 5715

"Carmen Sei" <fa**********@yahoo.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
Apr 4 '08 #2
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 "declaration".
Prototype is a C term.

Signature is something else.
Apr 4 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Michele Simionato | last post: by
8 posts views Thread by Squirrel | last post: by
4 posts views Thread by mrgr8avill | last post: by
1 post views Thread by Joe Fallon | last post: by
4 posts views Thread by John J. Hughes II | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.