와 코드를 고려 할 수 있습니다이유는 템플릿 매개 변수에 의해 친구 기능의 유형을 선언 할 수 있지만 별칭
template <class T>
class Bar {
int foobar;
using X = T();
friend X foo;
};
void foo() {
Bar<void> bar;
bar.foobar = 1;
static_cast<void>(bar);
}
int main() {}
는 gcc 및 clang 모두에서 잘 컴파일합니다. 그러나 겉보기에 상응하는 코드는 :
template <class T>
class Bar {
int foobar;
friend T foo;
};
void foo() {
Bar<void()> bar;
bar.foobar = 1;
static_cast<void>(bar);
}
int main() {}
는 gcc 및 clang 모두에서 오류가 발생합니다. 템플릿 매개 변수가 별칭과 동등하게 작동하지 않는 이유는 무엇입니까?
'void'를 한 번 보내고 다른 한 건은 void()로 보냅니다. – StoryTeller
"크래시"는 일반적으로 당신이 의미하는 바를 의미하지 않습니다. –
그리고 https://timsong-cpp.github.io/cppwp/temp#spec-7 –