Multiple File Compilation Problem

I was trying to create a simple AI based on some tutorial (the code is not mine, so it should be working), but it won't compile.
Here are my files:

voice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef _VOICE_H
#define _VOICE_H

#include <iostream>

using namespace std;

class Voice {
public:
    void say(string phrase);    // Used to textually and audibly communicate a phrase
};

#endif 

learner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef _LEARNER_H
#define _LEARNER_H

#include <iostream>
#include <fstream>
#include "voice.h"

using namespace std;

class Learner {
public:
    void respond(string phrase);    // Used to get, or teach a response
    void say(string phrase);    // Used to textually and audibly communicate a phrase

    Voice voice;    // The learner's voice that will audibly communicate a response
};

#endif 


voice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "Voice.h"
#include <iostream>
#include <windows.h>

using namespace std;

/*
	The following function textually and audibly communicates a phrase. 
	The open source eSpeak speech synthesizer is used to create the audible message. 
	If the eSpeak exe is not located in the directory, no audible message will be heard.  
*/
void Voice::say(string phrase){
    string command = "espeak \"" + phrase + "\"";    // Concat the phrase to the command
    const char* charCommand = command.c_str();    // Convert to a const char* 
    cout << phrase << endl;    // Textually output phrase
    system(charCommand);    // Send the command to cmd to execute espeak with the phrase an argument
}


learner.cpp
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
#include "learner.h"
#include <iostream>
#include <fstream>

using namespace std;
/*
    The following function will look for the passed phrase in the memory file.
    If there is a match, the accompanying response, stored below the initial phrase, 
    will be outputed. 
    If the response cannot be found, the learner will repeat the phrase, and prompt
    the user to enter an ideal response. This response will be stored in the memory
    file along with the initial phrase. 
*/
void Learner::respond(string phrase){
    fstream memory;
    memory.open("memory/memory.txt", ios::in);    // Open the memory file for input

    // Search through the file until the end is reached
    while( !memory.eof() ){    // While not at end of file
        string identifier;
        getline(memory,identifier);    // Get next phrase
        
        if(identifier == phrase){    // Is it the phrase we are looking for
            string response;
            getline(memory,response);   // If so, get the response
            voice.say(response);   // Textually and audibly output the response!
            return;    // Leave the function
        }
    }

    memory.close();    // Looks like we couldn't find the phrase in memory. Close the file!
    memory.open("memory/memory.txt", ios::out | ios::app);    // Now open for output, and append at end of file
    memory << phrase << endl;    // Record initial phrase in memory

    voice.say(phrase);   // Repeat the phrase the user entered
    string userResponse;
    cout << "YOU: ";
    getline(cin, userResponse);    // Get the ideal response
    memory << userResponse << endl;    // Write the ideal response to memory
    memory.close();    // Close the file!
}

/*
    This function simply communicates a phrase textually and audibly
*/
void Learner::say(string phrase){
    this->voice.say(phrase);
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include "learner.h"

using namespace std;

main(){
    Learner AI;    // Create a learner object

    /*
    	The following is the main loop. It will continue until the application is closed. 
    	The user enters their input, and then the learner will respond. 
    */
    for(;;){
        cout << "\nYOU: ";    // User prompt
        string phrase;
        getline(cin, phrase);    // Using getline for multi word input, then store in phrase. 
        
        cout << "COMPUTER: ";
        AI.respond(phrase);    // Pass the user input to the learner and see if he can respond
    }
}


When I try to compile one of the .cpp files it gives me a couple of "undefined reference to" errors. What am I doing wrong? I'n using Dev C++ 5.11
http://www.cplusplus.com/forum/general/113904/ (You forgot to link the file that defines it)
Topic archived. No new replies allowed.