undefined reference compiler error with cstring

I get this error and I have no idea why, this entire program uses cstrings, but when I create char word[constant] in this function it decides it hates me.


/tmp/ccCWsffn.o: In function `pickRandword(char*)':
madlibfx.cpp:(.text+0x22f): undefined reference to `pickAword(std::basic_istream<char, std::char_traits<char> >&)'
madlibfx.cpp:(.text+0x25b): undefined reference to `pickAword(std::basic_istream<char, std::char_traits<char> >&)'
madlibfx.cpp:(.text+0x287): undefined reference to `pickAword(std::basic_istream<char, std::char_traits<char> >&)'
madlibfx.cpp:(.text+0x2b3): undefined reference to `pickAword(std::basic_istream<char, std::char_traits<char> >&)'
madlibfx.cpp:(.text+0x2df): undefined reference to `pickAword(std::basic_istream<char, std::char_traits<char> >&)'
collect2: ld returned 1 exit status

and here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void pickAword(ifstream & streamName)
{
  char word[MAX_WORD];
  int number_words;
  int word_number;
  int newWordlength;
  streamName>>number_words; //reads the number of words in the file to choose from
  streamName.ignore();  //ignores the newline
  word_number = ((rand() % number_words)+1);
  for (int i=0; i<word_number; i++)
  {
    cout<<streamName.getline(word, MAX_WORD);  //goes down list till the random word is selected
  }  
  streamName.close();
    newWordlength = strlen(word);
  for (int j=0; j< newWordlength;j++)
    cout<<word[j];
}


help!?
Double check your prototype and make sure it matches your function body.

From the looks of your error it looks like your prototype is probably this:

void pickAword(istream & streamName);

but your function body has this:

void pickAword(ifstream & streamName)

(note: ifstream vs istream)

As a general rule of thumb, it's best to use the highest class in the hierarchy as possible, so unless you need something specific to ifstream, you're better off using istream for this function.
Thanks, I never woulda figured that one out.
Topic archived. No new replies allowed.