Dobrý deň,
potreboval by som poradiť ohladne jedného kódu. Píšem ho z knižky ale kompilátor mi vkuse vyhadzuje chybu a neviem prísť na to ako ju odstrániť. A už som aj hľadal na Googli ale nič mi neporadil.
Out-of-line definition of ' ' does not match any declaration in ' '.
Snažim sa skompilovať tento program. Programujem v Xcode.
//mytime.h -- Trieda Time pred priradenim operatoru
#ifndef time_hpp
#define time_hpp
#include <stdio.h>
class Time
{
private:
int hours;
int minutes;
public:
Time();
Time(int h, int m = 0);
void add_min(int m);
void add_hr(int h);
void reset(int h = 0, int m = 0);
Time Sum(const Time &t) const;
void show() const;
};
#endif
//mytime.hpp -- implementacia metody time
#include <iostream>
#include "time.hpp"
Time::Time()
{
hours = minutes = 0;
}
Time::Time(int h, int m)
{
hours = h;
minutes = m;
}
void Time::add_min(int m)
{
minutes += m;
hours += minutes / 60;
minutes %= 60;
}
void Time::add_hr(int h)
{
hours += h;
}
void Time::reset(int h, int m)
{
hours = h;
minutes = m;
}
Time Time::Sum(const Time &t) //-- tu my to hlási tu chybu.
{
Time sum;
sum.minutes = minutes + t.minutes;
sum.hours = hours + t.hours + sum.minutes / 60;
sum.minutes %= 60;
return sum;
}
void Time::show() const
{
std::cout << hours << " hodin, " << minutes << " minut." << std::endl;
}
// main.cpp
#include <iostream>
#include "time.hpp"
using namespace std;
int main()
{
Time planning;
Time coding(2, 40);
Time fixing(5, 55);
Time total;
cout << "planovanie = ";
planning.show();
cout << endl;
cout << "programovanie = ";
coding.show();
cout << endl;
cout << "ladenie = ";
fixing.show();
cout << endl;
total = coding.Sum(fixing);
cout << "coding.Sum(fixing) = ";
total.show();
cout << endl;
return 0;
}