Symbol not found Error

Being a beginner in c++ coming from a java background ,
I find the inheritance in c++ a bit confusing to implement.
I looked up at tutorials but none seemed to fix my problem .

Im trying to implement an alarm clock and normal clock .
Its a very basic program , heres the code for 3 of the classes , note in my program clock is a superclass of Normal Clock and Normal Clock is a superClass of Alarm Clock.


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
Clock.h
  class Clock
{
public:
    virtual void tick() = 0;
    void print() ;
    void setTime(int sec , int mins , int hours);
    int hour;
    int minute;
    int second;
    Clock();
    ~Clock();
};
clock.cpp

void Clock::print() {
    cout << hour <<":" << minute << ":" << second << endl;
}
void Clock::setTime(int sec , int mins , int hours) {
    second = sec;
    minute = mins ;
    hour = hours;

    if (second > 59) {
        second = 0 ;
        minute++;
    }
    if (minute > 59) {
        minute = 0;
        hour++ ;
    }
    if ( hour > 23)
        hour = 0;
}
Clock::Clock() {
    hour = 0 , minute = 0 , second = 0;
}
NormalClock.h

class NormalClock : public Clock
{
public:
    void tick() ;
    NormalClock();
    ~NormalClock();
};
NormalClock.cpp

 void NormalClock::tick() {
    second +=1 ;
    setTime(second,minute,hour);
}
AlarmClock.h

class AlarmClock : public NormalClock
{
public:
    int alarmSecond, alarmMinute, alarmHour;
    void tick();
    void checkTime();
    AlarmClock(); 
    ~AlarmClock();
};  
AlarmClock.cpp

 void AlarmClock::tick() {
    NormalClock::tick();
    checkTime();
}
void checkTime() {
    cout << "HELLO CHECKTIME" << endl;
}


I left out the constructors , destructors and imports to make it easier.

I am guessing that your code does not compile and that is the problem.

I modified the code you posted so that it compiles.

http://cpp.sh/8n3q
What's your question?
1) I do not see you including "clock.h" in NormalClock.h and "NormalClock.h" in AlarmClock.h
2) Did you add .cpp files to the project files (if you are using IDE)?
Thank you very much rafae11 ,
That helped a lot and worked ,
Your code runs perfectly!

just wondering what did you change in the code to make it compile because I cant fiind the part you changed.

And sorry for not clarifying the question clearly , the code wasn't compiling :D

Thanks again for the help,

peace,
Last edited on
1
2
3
4

//i just changed void checkTime()  to 

void AlarmClock::checkTime()
Topic archived. No new replies allowed.