OSX (clang) 및 Linux (GCC/Clang)에서 올바르게 컴파일되는 라이브러리를 빌드하려고합니다. MSVC/Visual Studio 2017에서 이해할 수없는 템플릿 정의를 발견했습니다. 다음과 같은 오류가MSVC : 인식 할 수없는 템플릿 선언/정의 (Clang/GCC로 컴파일)
#include "stdafx.h"
template<class T>
class Parent {
class Child {
friend class Parent;
public:
Child(const Child &r);
};
};
template<class T>
Parent<T>::Child::Child(const Parent<T>::Child &r) {
*this = r;
}
int main(int argc, char const *argv[]) {
/* code */
return 0;
}
이 (여전히) 결과 : 나는 그것을로 요약 할 수
는1>...consoleapplication1.cpp(13): error C2988: unrecognizable template declaration/definition
1>...consoleapplication1.cpp(13): error C2059: syntax error: '('
1>...consoleapplication1.cpp(13): error C2143: syntax error: missing ';' before '{'
1>...consoleapplication1.cpp(13): error C2447: '{': missing function header (old-style formal list?)
하지만 (여전히) 연타 또는 GCC와 OSX에 컴파일합니다. stdafx.h
및 main
은 실제 라이브러리 코드의 일부가 아니지만 VS Windows 명령 줄 프로젝트에서이 코드를 사용할 수 있도록 추가되었습니다.
무엇이 여기에 있습니까? MSVC는 템플릿의 멤버 클래스 또는 친구 선언에 문제가 있습니까?
[This] (https://godbolt.org/g/ZnwTFm)가 문제를 해결합니다. 그중 하나가 틀린 것 같습니다. –
@PasserBy :'const Parent :: Child'를'const * typename * Parent :: Child'로 변경하면 실제로 문제가 해결됩니다. 또한이 매우 유용한 온라인 컴파일러를 보여 주셔서 대단히 감사합니다. 나는 미래에 문제가 생길 때 그것을 확실히 사용할 것입니다. –
aleneum