An error appeared while I was testing the driver code. The compiler raised such an error:
undefined reference to Time::Time(int, int, int)
AND
undefined reference to Time::setTime(int, int, int)
Why did the Code::Blocks IDE raise this error? Is it due to the main or any declaration or definition errors? Please point out my error.
TIME.H
# ifndef TIME1_H
# define TIME1_H
class Time
{
public:
Time(int, int, int); // Default constructor
void setTime(int, int, int); // Set hour, minute, second
void printMilitary();
void printStandard();
private:
int hour;
int minute;
int second;
};
# endif
TIME.CPP
# include <iostream>
# include "TIME.H"
using namespace std;
// Implementing the functions
void Time::setTime(int hour, int minute, int second)
{
setTime(hour, minute, second);
}
void Time::printMilitary()
{
if(hour >= 1200 && hour <= 2359)
{
hour-1200;
cout << hour << ":" << minute;
}
if(hour < 1200 && hour >= 100)
{
cout << hour << ":" << minute << ":" << second << " AM";
}
else
{
cout << hour << ":" << minute << ":" << second;
}
}
void Time::printStandard()
{
if(hour)
{
cout << hour << ":" << minute << ":" << second;
{
}
}
MAIN.CPP
# include <iostream>
# include "TIME.H"
using namespace std;
int main()
{
Time a(0, 0, 0);
a.setTime(12, 23, 18);
return 0;
}
Are there any links to help?
When I tried the working demo posted by @Annop Raya, everything was fine when I ran the code. But when I try this code in Code::Blocks, it raised a few errors at the implementation file. The errors are shown below:
Line 6
error: 'Time' does not name a type; did you mean 'time'?
Line 11
error: 'Time' has not been declared
Line 17
error: 'Time' has not been declared
Line 17
In function 'void printMilitary()':
Line 19
'hour' was not declared in this scope
All the private member variables gets the same error, what's wrong?
In the main file, the compiler still returns the same error, so is there a solution for this?