g ++ / clang ++で動作するコードがあります。最近、Visual C ++で機能しないことが報告されました。
コードは次のとおりです。
namespace q {
template <typename X, typename Y>
struct A {};
}
template <typename X>
struct B {
template <typename Y>
friend struct q::A;
};
int main() {
return 0;
}
VC ++は次のエラーを返します。
source_file.cpp(9): error C2976: 'q::A': too few template arguments
source_file.cpp(3): note: see declaration of 'q::A'
source_file.cpp(10): note: see reference to class template instantiation 'B<X>' being compiled
誰が正しいですか?これを行うためのポータブルな方法はありますか?
テンプレートパラメータを適切に記述すると、次のことが役立ちます。
template <typename X, typename Y>
friend struct q::A;
A
友達として誤って宣言すると、プログラムの形式が正しくなくなるため、診断は必要ありません。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加