좀 도와주세요 왜 이런 오류가 나오는지 잘모르겠습니다.

asradad1의 이미지

monitior를 세마포어로 구현하려고 condition var를 만들었는데요.
constructor를 잘못 만들어서 그런거 같은데,
이런 오류가 나오네요 다음은 소스 코드입니다.
3 //semaphore를 초기화한다.
4 condition::condition()
5 {
6 sem_key = rand();
7 if(mutex = semget((key_t)sem_key, 0, 0666 | IPC_CREAT | IPC_EXCL) == -1)
8 {
9 printf("can't make semaphore");
10 return -1;
11 }
12 }

Quote:
condition.cpp:5: ISO C++ forbids defining types within return type
condition.cpp:5: return type specification for constructor invalid
condition.cpp: In constructor `condition::condition()':
condition.cpp:10: returning a value from a constructor
jachin의 이미지

7번 행에서 조건문의 식이

if ((mutex=semget((key_t)sem_key, 0, 0666 | IPC_CREAT | IPC_EXCL)) == -1)

가 되어야 하지 않을까요? 괄호가 조금... -_-a

alsong의 이미지

construct에서는 리턴을 할수 없습니다.

그나저나 백수 언제 탈출하냐... ㅡㅡ; 배고파라.

asradad1의 이미지

monitior를 세마포어로 구현하려고 condition var를 만들었는데요.
constructor를 잘못 만들어서 그런거 같은데,
이런 오류가 나오네요

Quote:

condition.cpp:5: ISO C++ forbids defining types within return type
condition.cpp:5: return type specification for constructor invalid

다음은 소스 코드입니다.
3 //semaphore를 초기화한다. 
4 condition::condition() 
5 { 
6 sem_key = rand(); 
7 if(mutex = semget((key_t)sem_key, 0, 0666 | IPC_CREAT | IPC_EXCL) == -1) 
8 { 
9 printf("can't make semaphore"); 
10 } 
11 } 

아까 꺼는 return문이 잘못들어가서 그랬더군요..
근데 왜 저 오류는 없어지지 않는건지-0-

asradad1의 이미지

어이없는 데에서 에러가 났군요..
헤더 class정의한 후에 ;를 빼먹었다는..-0-
근데 왜 constructor에서 에러를 내는지 이해가 잘 안되네요-0-

dyks의 이미지

선언부가 어떻게 되어있는지 궁금하네요.