string merge

C

Carmen Sei

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

Sharad

Carmen Sei said:
================
#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.h> for 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,949
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top