class Clock
{
public:
void set(int hour, int min, int sec);
int read_hour() {
return h;
}
int read_min() {
return m;
}
int read_sec() {
return s;
}
void write(bool write_sec = true);
void tick();
private:
int h,m,s;
};
inlinevoid Clock::set(int hour, int min, int sec)
{
h = hour;
m = min;
s = sec;
}
Unresolved external means that you've declared a function but not given it a body. Give Clock::tick() and Clock::write() a body just like you gave Clock::set a body here
1 2 3 4 5 6
inlinevoid Clock::set(int hour, int min, int sec)
{
h = hour;
m = min;
s = sec;
}
even if you aren't going to use those functions yet they need bodies.
#include <iostream>
#include <iomanip>
usingnamespace std;
class Clock
{
public:
void set(int hour, int min, int sec);
int read_hour() {
return h;
}
int read_min() {
return m;
}
int read_sec() {
return s;
}
void write(bool write_sec = true);
void tick();
private:
int h,m,s;
};
inlinevoid Clock::set(int hour, int min, int sec)
{
h = hour;
m = min;
s = sec;
}
void Clock::tick()
{
s = (s+1) % 60;
if(s == 0) {
m = (m+1) % 60;
if(m == 0) {
h = (h+1) % 60;
}
}
}
void Clock::write(bool write_sec)
{
cout << setw(2) << setfill('0') << h
<< ':' << setw(2) << setfill('0') << m;
if(write_sec)
cout << ':' << setw(2) << setfill('0') << s;
}
now the error is
1 2 3
1>main.obj : error LNK2005: "public: void __thiscall Clock::tick(void)" (?tick@Clock@@QAEXXZ) already defined in flight.obj
1>main.obj : error LNK2005: "public: void __thiscall Clock::write(bool)" (?write@Clock@@QAEX_N@Z) already defined in flight.obj
1>D:\C++ Projects\flights\Debug\flights.exe : fatal error LNK1169: one or more multiply defined symbols found