http://www.cplusplus.com/refer...
time은 time.h 에 이미 선언되어 있는 함수입니다.
굳이 time 이름을 사용하고 싶으시다면, 변수를 선언할 때 C 스타일을 사용하셔야 합니다.
ex) struct time t();
http://www.cplusplus.com/refer...
time은 time.h 에 이미 선언되어 있는 함수입니다.
굳이 time 이름을 사용하고 싶으시다면, 변수를 선언할 때 C 스타일을 사용하셔야 합니다.
ex) struct time t();
감사합니다!!
댓글을 작성하려면 로그인해야 합니다.
fairy_of_9 8년 전
vs에서는 잘 돌아가는데 백준에서는 컴파일 에러가 나네요..ㅠㅠㅠ 버전도 cpp17로 잡았는데 말이죠...
#include<iostream>
#include<algorithm>
using namespace std;
struct time
{
int s;
int t;
};
bool cmp_time(time a, time b)
{
if (a.s == b.s)
return a.t < b.t;
return a.s < b.s;
}
int main()
{
int n, max_room = 0, i, j;
cin >> n;
time* times = new time[n];
for (i = 0; i < n; i++)
cin >> times[i].s >> times[i].t;
sort(times, times + n, cmp_time);
for (i = 0; i < n; i++)
{
for (j = 0; j < i; j++)
{
//추가된 과목의 시작시간이 기존 과목의 마침 시간보다 늦을 시 == 추가x
if (times[i].s >= times[j].t)
break;
}
if (j == i) //이전 과목들과 시간이 무조건 겹친다
max_room++;
}
printf("%d\n", max_room);
delete[] times;
return 0;
}
에러 로그는 아래와 같습니다.
Main.cc:13:20: error: expected ‘)’ before ‘a’ bool cmp_time(time a, time b) ^ Main.cc:13:28: error: expected ‘)’ before ‘b’ bool cmp_time(time a, time b) ^ Main.cc:13:29: error: expression list treated as compound expression in initializer [-fpermissive] bool cmp_time(time a, time b) ^ Main.cc:13:29: warning: left operand of comma operator is a reference, not call, to function ‘time’ [-Waddress] Main.cc:13:29: warning: left operand of comma operator has no effect [-Wunused-value] Main.cc:13:29: warning: the address of ‘time_t time(time_t*)’ will never be NULL [-Waddress] Main.cc:13:29: warning: the address of ‘time_t time(time_t*)’ will never be NULL [-Waddress] Main.cc:14:1: error: expected ‘,’ or ‘;’ before ‘{’ token { ^ Main.cc: In function ‘int main()’: Main.cc:25:8: error: ‘times’ was not declared in this scope time* times = new time[n]; ^~~~~ Main.cc:25:8: note: suggested alternative: ‘time’ time* times = new time[n]; ^~~~~ time Main.cc:25:20: error: ‘time’ does not name a type time* times = new time[n]; ^~~~ Main.cc:46:11: error: type ‘<type error>’ argument given to ‘delete’, expected pointer delete[] times; ^~~~~