G++ Compiler Error: undefined reference to (a function)

Hey all,

I've searched the archives, the web, and other Linux/Programming websites' forums and I haven't been able to find my answer. I am writing a program that uses functions for different tasks. The first task is to count the number of consonants in a string. I'm getting a compiler error:
program.cpp:(.text+0x6b): undefined reference to `count_vowels(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

Here is the code I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
using namespace std;

int count_vowels(int,string);
int count_cons(int,string);
void strip_symbols(string);
void format_word(string);

int main()
{
  int wordnum=0;    //num of words
  int vowelnum=0;   //num of vowels
  int consnum=0;    //num of consonants
  string word;  

  cin >> word;

  while (!cin.eof())
    {
      //~~~~~~~~~~~~~~~~~~~~~COUNTING OPERATIONS ~~~~~~~~~~~~~~~~~~~~~
      vowelnum = vowelnum + count_vowels(vowelnum,word);
      consnum = consnum + count_cons(consnum,word);
      //--------------------------------------------------------------
      //--------------------------------------------------------------

      //~~~~~~~~~~~~~~~~~~~~~WORD CONVERSION SECTION~~~~~~~~~~~~~~~~~~
      strip_symbols(word);
      format_word(word);

      cout << word << " ";
      wordnum++;
      cin >> word;
    }
  
  return 0;
}

int count_cons(int num,string text)
{
  int i=0;
  int wlen = text.length();
  while (i<(wlen-1))
    {
      cout << text[i] <<endl;
      i++;
    }
  return num;
}



I know that the above code will not complete the task of counting consonants, but if I can't write a simple function to do a simple action like above, I sure as heck won't be able to write the more complex task of counting consonants.

I have been at this for way too long... a few hours already just trying to figure out what the problem is. I fear it's something extremely simple or something that should pop out right before me.
I really, really will appreciate any help.

Thanks!
Well, you're calling count_vowels, but you never defined it. How do you expect that to work?
Wow, well I feel like a moron. I guess I didn't understand that it won't compile without having a definition.. I commented out vowel_num() and the other two functions I didn't define (yet), and all is well.

Thank you!
Topic archived. No new replies allowed.