は、次の例を取ることはありません:g++-5
でグラム++ - 影のテンプレートパラメータに6エラーG ++ながら - 5
#include <vector>
template <typename T, template <class T> class Container>
std::vector<T> To_Vector(Container<T> const& c){
return std::vector<T>(c.begin(), c.end());
}
int main(){}
を、それがエラーなしでコンパイル:g++-6
で
はコンパイルに失敗しています:
g++-6 -o main main.cpp
main.cpp:4:33: error: declaration of template parameter ‘T’ shadows template parameter
template <typename T, template <class T> class Container>
^~~~~
main.cpp:4:11: note: template parameter ‘T’ declared here
template <typename T, template <class T> class Container>
コンパイラが間違っていますか?私のコードは間違っていますか?
g++-6
はなぜg++-5
はこのコードをコンパイルしますか?
g++-5 --version
g++-5 (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++-6 --version
g++-6 (Ubuntu 6.2.0-3ubuntu11~14.04) 6.2.0 20160901
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@skypjackだから、ちょうどが私のために構築するので、私はに 'T'を残すべきです。 –
これは有効かつ有効な解決策です。あなたの例では 'T'は役に立たないのですか? – skypjack
@skypjackあなたが正しいです。コンテナの型名は型Tに特化しなければならないと考えるのは混乱していたに違いないが、実際のパラメータでは起こる。 –