I'd like to declare a function in my main.cpp
, so that my main
function can be the first one in the file. It looks like this:
main.cpp
#include <iostream>
#include <string>
using namespace std;
string my_function();
int main () {
my_function();
return 0;
}
string my_function(string message = "") {
string response;
cout << message;
getline(cin,response);
return response;
}
However, when compiling I get an error:
/usr/bin/ld: /tmp/cco8jyj1.o: in function `main':
main.cpp:(.text+0x1f): undefined reference to `my_function[abi:cxx11]()'
collect2: error: ld returned 1 exit status
[Finished in 1.4s with exit code 1]
What is wrong?