LNK2019 Error

I'm fairly new to C++ and I've been having an LNK error without knowing what to do. I've listed the code, class file and errors below. I have the header as Rectangle.h so that's not the problem. Any help would be greatly appreciated!

Here are the errors:

Error 1 error LNK2019: unresolved external symbol "void __cdecl getArea(void)" (?getArea@@YAXXZ) referenced in function _main

Error 2 error LNK2019: unresolved external symbol "void __cdecl displayData(void)" (?displayData@@YAXXZ) referenced in function _main

Error 3 error LNK1120: 2 unresolved externals


Here is the class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#ifndef RECTANGLE_H
#define RECTANGLE_H

class Rectangle
{

private:
	double width;
	double length;
	double area;
public:
	void setWidth(double, double) const;
	void setLength(double, double) const;
	double getWidth(double) const;
	double getLength(double) const;
	double getArea(double, double);
	void displayData(double, double, double);

};

#endif 






Here is the code:

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Rectangle.h"
#include <iostream>
#include <cstdlib>
using namespace std;

void getLength();
void getWidth();
void getArea();
void displayData();

int main()
{
	cout << "This program calculates the area of a rectangle./n";

	getLength();
	getWidth();
	getArea();
	displayData();

	return 0;

}

void Rectangle::setWidth(double w, double width) const
{
	if (w > 0)
		width = w;
	else
	{
		cout << "Invalid width.\n";
		exit(EXIT_FAILURE);
	}
}

void Rectangle::setLength(double len, double length) const
{
	if (len > 0)
		length = len;
	else
	{
		cout << "Invalid length.\n";
		exit(EXIT_FAILURE);
	}
}

double Rectangle::getWidth(double width) const
{
	return width;
}

double Rectangle::getLength(double length) const
{
	return length;
}

double Rectangle::getArea(double width, double length)
{
	return width * length;
}

void getWidth()
{
	double width;

	cout << "What is the width of the rectangle?";
	cin >> width;

}

void getLength()
{
	double length;

	cout << "What is the length of the rectangle?";
	cin >> length;

}

void getArea(double length, double width)
{
	double area;

	area = length * width;

}

void displayData(double width, double length, double area)
{
	cout << "The length is " << length << "./n";
	cout << "The width is " << width << "./n";
	cout << "The area is " << area << "./n";

}
1) you need to add the scope resolution operator '::' on some of your functions in the .cpp file ill do the first one for you

2) your return types do not match

3) remove these functions from main. these have been included from your header file "Rectangle.h"...These are declared wrong too..they don't match your original prototype in your header file for rectangle
1
2
3
4
void getLength();
void getWidth();
void getArea();
void displayData();


**All functions related to Rectangle class really should be coded in a file called "Rectangle.cpp" but whatever should still work I guess..
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
double Rectangle::getWidth() // added scope reso operator and changed void to double 
{
	double width;

	cout << "What is the width of the rectangle?";
	cin >> width;

}

void getLength()
{
	double length;

	cout << "What is the length of the rectangle?";
	cin >> length;

}

void getArea(double length, double width)
{
	double area;

	area = length * width;

}

void displayData(double width, double length, double area)
{
	cout << "The length is " << length << "./n";
	cout << "The width is " << width << "./n";
	cout << "The area is " << area << "./n";

}
Last edited on
Thanks, I actually figured out that I way over-thought this and the solution is much simpler.
Topic archived. No new replies allowed.