gpt4 book ai didi

c++ - g++-6 阴影模板参数错误,而 g++-5 没有

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:55 25 4
gpt4 key购买 nike

<分区>

举个例子:

#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++-5,编译没有错误:

g++-5 -o main main.cpp 

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++-5 编译这段代码而 g++-6 不编译?


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.

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com