Program w Visual Studio działa, ale już na Ideone nie kompiluje się

0
#include <iostream>
#include <string>

using namespace std;

class time
{
public:
	time(){}
	int hour;
	int minute;
};

ostream & operator<<(ostream &out, time &a)
{
	if (a.hour <= 9)
		out << 0 << a.hour << ":";
	else
		out << a.hour << ":";
	if (a.minute <= 9)
		out << 0 << a.minute;
	else
		out << a.minute;
	return out;
}

istream & operator>>(istream &in, time &a)
{
	string x;
	in >> x;

	if (x[0] == 0)
		a.hour = x[1] - 48;
	else
		a.hour = (x[0] - 48) * 10 + x[1] - 48;

	if (x[3] == 0)
		a.minute = x[4] - 48;
	else
		a.minute = (x[3] - 48) * 10 + x[4] - 48;

	return in;
}

time operator+(time t1, time t2)
{
	time t3;
	t3.hour = t1.hour + t2.hour;
	if (t3.hour >= 24)
		t3.hour -= 24;
	t3.minute = t1.minute + t2.minute;
	while (t3.minute >= 60)
	{
		t3.hour++;
		t3.minute -= 60;
	}

	return t3;
}

time operator+(time t1, int b)
{
	t1.minute += b;

	while (t1.minute >= 60)
	{
		t1.hour++;
		t1.minute -= 60;
	}

	while (t1.hour >= 24)
	{
		t1.hour -= 24;
	}

	return t1;
}

int main()
{
	time t; cin >> t;
	cout << t << ",";
	int a;

	while (cin >> a)
	{
		t = t + a;
		cout << t << ",";
	}

	return 0;
}
 

Mam tu napisany program do zadania na SPOJU
http://pl.spoj.com/problems/WI_DZWON/

W VC++ wszystko mi działa a na Ideone pokazuje, że błąd kompilacji
http://ideone.com/CVM37y

Dlaczego tak się dzieje?

2
  1. Zapoznaj się z inkrementacją bo jej nie rozumiesz: http://4programmers.net/Forum/1101404
  2. Prawdopodobnie w implementacji gcc kompilator "widzi" funkcje time() więc zmień nazwę na Time i ...: http://ideone.com/9p9y96
  3. Spójrz sobie na to:
#include <stdio.h>

void show(unsigned m,int sh)
  {
   unsigned h=m/60;
   printf(",%02d:%02d"+sh,h%24,m-60*h);
   h=(m+=45)/60;
   printf(",%02d:%02d",h%24,m-60*h);
  }
 
int main()
  {
   unsigned h,m;
   scanf("%u:%u",&h,&m);
   m+=60*h;
   show(m,1);
   while(scanf("%u",&h)==1) show(m+=45+h,0);
   return 0;
  }

1 użytkowników online, w tym zalogowanych: 0, gości: 1