-
Cannot initialize a variable of type 'int' with an rvalue of type 'void *' 에러 해결법알고리즘/정리 및 오류 해결 방법 2018. 12. 9. 16:58반응형
변수 선언 오류
Cannot initialize a variable of type 'int' with an rvalue of type 'void *' 와 같은 에러는 흔히
malloc() 과 같은 함수를 통해 변수를 선언할때 자주 발생한다.
ex)
> int temp = malloc(sizeof(int));
> Cannot initialize a variable of type 'int' with an rvalue of type 'void *'
이러한 경우의 이유는
malloc() 함수로 선언되는 경우에는 void* 형식으로 선언이 되어 int 변수에 할당할 수가 없기 떄문에 발생한다.
따라서 (int*) 와 같은 식으로 변환을 시킨 뒤 선언해 주면 할당된다.
> int* temp = (int*)malloc(sizeof(int));
반응형'알고리즘 > 정리 및 오류 해결 방법' 카테고리의 다른 글
댕글링 포인터 문제: free 함수를 이용해도 계속 호출 되는 문제 (0) 2018.12.09 c++ malloc() 함수 설명 (0) 2018.12.09 std::cout string int 같이 쓰는 법 (0) 2018.11.25 c++ 에서 using namespace 를 장려하지 않는 이유 (0) 2018.11.25 c++ 오류 해결법 : Use of undeclared identifier '함수명' (0) 2018.11.20