Unresolved external symbol..Help please

My program calls for me to create a base class Clock, a derived class AccurateClock, and to access them in main, but I'm getting two "LNK2019: unresolved external symbol" errors. I really don't know what to do to fix those. Any help is appreciated!

I have 5 different code sections, so I'll just post the main and the 2 .cpp for right now.

This is my main, Clock.cpp, and AccurateClock.cpp. The main is supposed to feed numbers into the classes and print them on screen.

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
#include "Clock.h"
#include "AccurateClock.h"
#include <iostream>

using namespace std;

int main()
{
	Clock clock1;
	AccurateClock clock2;
	AccurateClock clock3;

	clock1.setHour(23);
	clock1.setMinute(59);
	clock1.printTime();
	clock1.setHour(20);
	clock1.setMinute(56);
	clock1.printTime();

	clock2.setHour(7);
	clock2.setMinute(45);
	clock2.setSeconds(30);
	clock2.printTime();
	clock2.getAMPM(7);
	clock2.setHour(8);
	clock2.setMinute(40);
	clock2.setSeconds(25);
	clock2.printTime();
	clock2.getAMPM(8);

	clock3.setHour(12);
	clock3.setMinute(59);
	clock3.setSeconds(58);
	clock3.printTime();
	clock3.getAMPM(12);
	clock3.setHour(12);
	clock3.setMinute(20);
	clock3.setSeconds(58);
	clock3.printTime();
	clock3.getAMPM(12);
	

	system("pause");
	return 0;
}



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
#include "Clock.h"
#include <iostream>
#include <cstdlib>

using namespace std;



	void Clock::setHour(int h)
	{
		hour = h;
	}

	void Clock::setMinute(int m)
	{
		minute = m;
	}
	int Clock::getHour() const
	{
		return hour;
	}
	int Clock::getMinute() const
	{
		return minute;
	}

	void Clock::printTime()
	{
		if (hour >= 0 && hour <= 23)
			cout << hour << ":";
		else
		{
			cout << "Invalid hour\n";
		}
		if (minute >= 0 && minute <= 59)

			cout << minute << endl;
		else
		{
			cout << "Invalid minute\n";
		}
	}



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
#include "AccurateClock.h"
#include <iostream>
#include <cstdlib>

using namespace std;

	
	void AccurateClock::setSeconds(int s)
	{
		if (second < 0 || second > 59)
			{
			cout << "Second is invalid\n";
			}
		else
			second = s;
	}

	void AccurateClock::getAMPM(int hour)
	{
		if (hour < 12)
			cout << "AM\n";
		else
			cout << "PM\n";
	}

	void AccurateClock::printTime()
	{
		cout << hour << ":" << minute << ":" << second;

	}
What external symbol is unresolved?

At least I do not see the definition of Clock::setSeconds in Clock.cpp.
Last edited on
besides that. please provide your header as well.

that external symbol properly is from your header function
Usually, that error means that you've declared some function in the class, but haven't defined it. As vlad said, it might be that you didn't define it, or maybe you didn't compile the .cpp file that contains the definition.

Specific error lines are useful if that doesn't solve your problem.
Here's the errors I'm getting and the headers:

Pass8Q2.obj : error LNK2019: unresolved external symbol "public: __thiscall AccurateClock::AccurateClock(void)" (??0AccurateClock@@QAE@XZ) referenced in function _main

Pass8Q2.obj : error LNK2019: unresolved external symbol "public: __thiscall Clock::Clock(void)" (??0Clock@@QAE@XZ) referenced in function _main


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
#ifndef Clock_H
#define Clock_H
#include<iostream>

using namespace std;

class Clock
{
public:
	int hour;
	int minute;
	Clock();
	Clock(int h, int m)
	{
		int hour = h;
		int minute = m;
	}
	virtual void printTime();
	void setHour(int);
	void setMinute(int);
	int getHour() const;
	int getMinute() const;

};

#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
#ifndef AccurateClock_H
#define AccurateClock_H
#include "Clock.h"
#include <iostream>

using namespace std;

class AccurateClock : public Clock
{
public:
	int second;
	string ap;
	AccurateClock();
	AccurateClock(int h, int m, int s)
	{
		hour = h;
		minute = m;
		second = s;
	}
	void setSeconds(int);
	void getAMPM(int);
	virtual void printTime();

};

#endif 
I'm looking, but I'm not finding what I did wrong. I'll keep trying, though.
I don't think setSeconds is supposed to be in my base class, because I think it's specific to the AccurateClock.
THe problem is that you have not defined the two default constructors.
Oh, wow, sorry about that. I thought that when you write that the compiler automatically sets the body to NULL. Turns out you're not supposed to write it at all...sorry, and thanks!
Topic archived. No new replies allowed.