G++ error undefined reference

I looked at a bunch of the stackoverflow question already answered about this but they all seem to be dealing with header files and multiple .cpp files in one compilation. How can i get these headers to compile.

my error is
test.cpp:(.text+0x2b3): undefined reference to `userInput(std::string)'
collect2: error: ld returned 1 exit status

1
2
3
4
void userInput (const std::string);
userInput (array[number][dificulty]);
void userInput(const std::string &word)


these are some of the pages i checked
http://stackoverflow.com/questions/3656050/c-undefined-reference-to-foofoostdstring
http://stackoverflow.com/questions/7628779/c-undefined-reference-to-an-object
did you include string?

 
#include <string> 
Last edited on
Undefined reference means that you haven't defined how a function should work, meaning, there is no code for that function, just the declaration, aka prototype. If the function is defined in an external file, you need to include that during the compiling process. If you haven't defined it yet, you need to define it.

From the code snippet you supplied, userInput isn't defined.

A function prototype:
void userInput (const std::string inString);

A function definition:
1
2
3
void userInput (const std::string inString) {
   std::cout << "Your string is: " << inString;
}


A function call:
userInput("MyString");
Topic archived. No new replies allowed.