Reputation: 53
I have an issue compiling and running the code on visual studios. It gives me the error code "declaration is incompatible with" so and so. More specifically, when calling on the header in the code in the beginning of each function from the main CPP. I've tried changing the void to int in the header, but it didn't seem to fix it. I'm stuck now and need some guidance.
The error is: "Severity Code Description Project File Line Suppression State Error (active) E0147 declaration is incompatible with "void convertTime::invalidHr(int hour)" (declared at line 9 of "Time.h") Source.cpp 6 "
#include <iostream>
#include "Time.h"
using namespace std;
int convertTime::invalidHr(int hour) *//error on this line*
{
int convertHour = hour;
try
{
if (hour < 13 && hour > 0)
{
hour = hour + 12;
return hour;
}
else {
cin.clear();
cin.ignore();
cout << "Invalid input! Please input hour again in correct 12 hour format: ";
cin >> hour;
invalidHr(hour);
throw 10;
}
}
catch (int c) { cout << "Invalid hour input"; }
}
int convertTime::invalidMin(int min) *//error here*
{
int convertMin = min;
try
{
if (min < 60 && min > 0)
{
return min;
}
else {
cin.clear();
cin.ignore();
cout << "Invalid input! Please input minutes again in correct 12 hour format: ";
cin >> min;
invalidMin(min);
throw 20;
return 0;
}
}
catch (int e) { cout << "Invalid minute input" << endl; }
}
int convertTime::invalidSec(int sec) *//error here*
{
int convertSec = sec;
try
{
if (sec < 60 && sec > 0)
{
return sec;
}
else {
cin.clear();
cin.ignore();
cout << "Invalid input! Please input seconds again in correct 12 hour format: ";
cin >> sec;
invalidSec(sec);
throw 30;
return 0;
}
}
catch (int t) { cout << "Invalid second input" << endl; }
}
void convertTime::printMilTime()
{
cout << "Converted time: " << hour << ":" << min << ":" << sec;
}
And here is my header:
class convertTime
{
public:
int hour, min, sec;
void invalidHr(int hour);
void invalidMin(int min);
void invalidSec(int sec);
void printMilTime();
};
Upvotes: 3
Views: 37480
Reputation: 206737
The return types of the member functions don't match.
In the class definition, you have:
void invalidHr(int hour);
void invalidMin(int min);
void invalidSec(int sec);
In the implementations, you have:
int convertTime::invalidHr(int hour) { ... }
int convertTime::invalidMin(int min) { ... }
int convertTime::invalidSec(int sec) { ... }
You need to change one of them so they match.
Upvotes: 2