undefined reference to function - can't find cause

As part of a larger program I've started writing some stubs of a few functions, but even before I've filled in these stubs I'm already getting an undefined reference error:

main.cpp:line 17: undefined reference to encrypt(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
collect2: ld returned 1 exit status

I've checked that string is defined, my namespaces are the same, the #include's match the header file, the function names and parameter lists match the header file, but the error is still happening.

I can't figure out what is causing this. Can somebody help me? I'd really like to get on with this. (It's something obvious that I've overlooked, isn't it?)

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

using namespace std;

#include "caesar.h"

/*
 * 
 */
int main(int argc, char** argv) {

    cout << "hello warld." << endl;

    string plainText = "helloWarld";
    string cipher;
    cipher = encrypt(plainText);
    
    return 0;
}


caesar.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "caesar.h"
using namespace std;

string encrypt(string plainText)
{
    string cipherText = "myCipherText";


    return cipherText;
}

string decrypt(string cipherText)
{
    string plainText = "myPlainText";

    return plainText;
}

caesar.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef CAESAR_H
#define	CAESAR_H
#include <string>
using namespace std;

/*
static class caesar
{
    public:
        string encrypt(string);
        string decrypt(string);
};
*/

 string encrypt(string);
 string decrypt(string);

#endif	/* CAESAR_H */ 
for starter i'd get my spelling right....
Warld
...... dont know where you learned english.
"Hello Warld" is actually an in-joke.
Well, it started as one but now it seems to have become a habit.
Last edited on
Are you compiling and linking caesar.cpp?
The problem was with the IDE I was using.
Topic archived. No new replies allowed.