linked error

what's wrong with this program?? Here is the problem:

[Linker error] undefined reference to `incrementMinutes(Time&, int)'
ld returned 1 exit status

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <conio.h>

using namespace std;

class Time {
             int hour;
             int minute;
             int second;
      public:
             Time(int = 0, int = 0, int = 0); // construtor
             
             void setTime(int, int, int);
             void setHour(int);
             void setMinute(int);
             void setSecond(int);
             
             int getHour();
             int getMinute();
             int getSecond();
             
             void printMilitary(); // formato militar
             void printStandard(); // formato padrĂ£o
};

Time::Time(int hr, int min, int sec) {
           setTime(hr, min, sec);
}

void Time::setTime(int h, int m, int s) {
     setHour(h);
     setMinute(m);
     setSecond(s);
}

void Time::setHour(int h) {
     hour = (h >= 0 && h < 24) ? h : 0;
}

void Time::setMinute(int m) {
     minute = (m >= 0 && m < 60) ? m : 0;
}

void Time::setSecond(int s) {
     second = (s >= 0 && s < 60) ? s : 0;
}

int Time::getHour() { return hour; }

int Time::getMinute() { return minute; }

int Time::getSecond() { return second; }

void Time::printMilitary() {
     cout << (hour < 10 ? "0" : "") << hour << ":"
          << (minute < 10 ? "0" : "") << minute;
}

void Time::printStandard() {
     cout << ((hour == 0 || hour == 12) ? 12 : hour % 12)
          << ":" << (minute < 10 ? "0" : "") << minute
          << ":" << (second < 10 ? "0" : "") << second
          << (hour < 12 ? " da manha" : " da tarde");
}

void incrementMinutes(Time &, const int);

int main() {
    Time t;
    
    t.setHour(17);
    t.setMinute(34);
    t.setSecond(25);
    
    cout << "Resultado da inicializacao com todos os valores validos:\n"
         << " Hora: " << t.getHour()
         << " Minuto: " << t.getMinute()
         << " Segundo: " << t.getSecond();
         
    t.setHour(234);
    t.setMinute(43);
    t.setSecond(6373);
    
    cout << "\n\nResultado de tentar inicializar hora e segundo "
         << "invalidos:\n Hora: " << t.getHour()
         << " Minuto: " << t.getMinute()
         << " Segundo: " << t.getSecond() << "\n\n";
         
    t.setTime(11, 58, 0);
    incrementMinutes(t, 3);
    
    getch();
    return 0;
};

void incrementeMinutes(Time &tt, const int count) {
     cout << "Incrementando minuto " << count
          << " vezes:\nHora de inicio: ";
     tt.printStandard();
     
     for (int i = 0; i < count; i++) {
         tt.setMinute((tt.getMinute() + 1) % 60);
         
         if (tt.getMinute() == 0)
            tt.setHour((tt.getHour() + 1) % 24);
         
         cout << "\nminuto + 1 ";
         tt.printStandard();
     }
     
     cout << endl;
}
Last edited on
You have a typo. Where you have defined incrementMinutes, you have accidentally put incrementeMinutes. Remove the extra 'e'!

Because of this the linker cannot find a definition of the function incrementMinutes because there is no definition - only a definition of incrementeMinutes.

Hope this helps.
Topic archived. No new replies allowed.