이 문제는 MacOS에서만 나타나는 것으로 보이며, clang을 사용하여 Linux에서도 문제가 없습니다.MacOS에서 Clang 컴파일 오류가 발생했습니다
clang++ -std=c++11 main.cpp -o test
:이 사용 된 컴파일러 인수했다
main.cpp:2:5: error: redefinition of 'index' as different kind of symbol
int index = 0;
^
/usr/include/strings.h:73:7: note: previous definition is here
char *index(const char *, int) __POSIX_C_DEPRECATED(200112L);
^
main.cpp:5:18: warning: address of function 'index' will always evaluate to
'true' [-Wpointer-bool-conversion]
std::cout << index << std::endl;
~~ ^~~~~
main.cpp:5:18: note: prefix with the address-of operator to silence this warning
std::cout << index << std::endl;
^
&
1 warning and 1 error generated.
:
다음 코드
#include<iostream>
int index = 0;
int main()
{
std::cout << index << std::endl;
}
컴파일에 오류가 발생, 단순화하지만 문제를 보여줍니다 stdio로 iostream을 제거하거나 코드가 예상대로 컴파일되지 않습니다. 이 문제를 해결할 수있는 방법인가요? 또는이를 피하기 위해 변수 이름을 변경해야합니까?
나는 this을 찾았지만 이미 C++ 11 플래그를 사용하고 있으며 -std = c11 플래그가 C++ 코드에 유효하지 않은 것으로 보입니다.
왜 컴파일이 기대 되나요? – juanchopanza
'index'는 무엇이라고 생각하십니까? –
분명히 코드를 다시 타이핑하고 있습니다. 그렇게하지 마십시오. 복사하여 붙여 넣기를 사용하여 게시하십시오. –