LNK2019 error

I cannot find the mistake.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef GROUP38_TASK4_CAESAR_H
#define GROUP38_TASK4_CAESAR_H
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<cmath>

using namespace std;
class Caesar {
private:
	int key;
public:
	Caesar(int x);
	string encode(string me);
	
	string decode(string op);

	int changekey(int p);
	
};
#endif

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
#include"group38_task4_caesar.h"
#include<iostream>
using namespace std;
Caesar::Caesar(int x) {
	key = x;
}
int key;
string encode(string me)
{
	int i;
	for (i = 0; i < me.length(); i = i++) {
		me[i] = toupper(me[i]);
	}
	for (int i = 0; i < me.size(); ++i)
	{
		if (!((me[i] >= 'a' && me[i] <= 'z') || (me[i] >= 'A' && me[i] <= 'Z')))
		{
			me[i] = '\0';
		}
	}
	//me.erase(std::remove_if(me.begin(), me.end(), ::isspace), me.end());

	/*cout << me<<"\n";*/


	string code = "";
	for (i = 0; i < me.length(); i++) {
		if (me[i] != '\0') {
			code += char(int(me[i] + key - 65) % 26 + 65);
		}
	}
	return code;


}
string decode(string op) {
	string me = "";
	for (int i = 0; i < op.length(); i++) {
		me += char(int(op[i] - key + 65) % 26 + 65);
	}
	return me;
}

int changekey(int p) {
	key = p;
	return key;
}


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
54
55
56

#include "group38_task4_caesar.h"
#include<iostream>


int main(){
	char antwort,other_key;
	string me,code;
	int u,c;
	cout << "Hausaufgabe Nr. 2, Gruppe 38,Gruppenmitglieder: Parth Patel(385321),Yogesh Rao(388949), Nina Schnier.\n";
	cout << "Do you want encode ?y/n\n";
	cin >> antwort;
	cin.ignore();
	Caesar Boy(0);
	if (antwort == 'y' || antwort == 'Y') {
		cout << "Enter your message.\n";
		getline(cin, me);
		cout << "Enter the key.\n";
		cin >> u;
		Boy.changekey(u);
		cout <<"Your code is: "<< Boy.encode(me)<<"\n";
	}
	else if(antwort=='n'||antwort=='N'){
		cout << "Enter your code.\n";
		getline(cin, code);
		cin.ignore();
		cout << "Enter the key.\n";
		cin >> u;
		Boy.changekey(u);
		cout << "Your message is: " << Boy.decode(code)<<"\n";
}
	cout << "Do you want to change the key?y/n\n";
	cin >> other_key;
	if (other_key == 'y' || other_key == 'Y') {
		cout << "Enter the new key.\n";
		cin >> c;
		Boy.changekey(c);
		if (antwort == 'y' || antwort == 'Y') {
			cout << "Your new code is: " << Boy.encode(me)<<"\n";
		}
		else {
			cout << "Your new message is: " << Boy.decode(code)<<"\n";
		}
	}
	else{
		return 0;
		
	}
		system("pause");
	}





LNK2019: unresolved external symbol
1. Look at the name printed in the error message.

2. Look at what you wrote in the code.

3. Check that you've got
- the spelling right
- the capitalisation right
- the parameter types right.

And next time, post the FULL ACTUAL error message, not vague "LNK2019".
You haven't defined functions
1
2
3
string Caesar::encode(string me);
string Caesar::decode(string op);
int Caesar::changekey(int p);

(Yes, really: look closely).


Also:
for (i = 0; i < me.length(); i = i++)
Your compiler SHOULD complain about the
i=i++
where should I define them
in the second .cpp??
Yes, you should put the Caesar:: bit in the place where you actually write the code for them (the second code snippet that you give).

Make sure you fix the other error noted as well.

BTW it would massively help if you put everything in one file for the purposes of getting help on the forum. Then it can be run as-is in cpp.sh without having to download multiple files or cut and paste several separate includes into cpp.sh.

As @salem c noted, you should give the whole error message, whether you understand it or not.
Last edited on
ok thanks it works now
Topic archived. No new replies allowed.