First c++ program with .h file won't compile
OK, so I'm learning C++ and am trying to compile my first main.cpp and *.h file and am getting errors. The code was downloaded from the official site for the book that I'm using so I'm assuming there are no errors, but... it won't compile!!! What am I doing wrong?? Or does the program have errors in it?
Files:
main.cpp:
#include <iostream>
using namespace std;
#include "ccc_time.h"
int main()
{
Time wake_up(5, 6, 7);
wake_up.add_seconds(1000);
cout << wake_up.get_hours() << ":" << wake_up.get_minutes() << ":" << wake_up.get_seconds() << endl;
system("pause");
return (0);
}
ccc_time.h:
#ifndef CCC_TIME_H
#define CCC_TIME_H
class Time
{
public:
Time(int hour, int min, int sec);
Time();
int get_hours() const;
int get_minutes() const;
int get_seconds() const;
int seconds_from(Time t) const;
void add_seconds(int s);
private:
int time_in_secs;
};
#endif
Error I get:
[Linker error] undefined reference to 'Time::Time(int, int, int)'
[Linker error] undefined reference to 'Time::add_seconds(int)'
[Linker error] undefined reference to 'Time::get_seconds() const'
[Linker error] undefined reference to 'Time::get_minutes() const'
[Linker error] undefined reference to 'Time:: get_hours() const'
ls returned 1 exit status
I've tried compiling using g++ from command line, using Bloodshet Dev C++, and using Anjuta. I just can't seem to get it to work. What's wrong?
Thanks.
|