首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

~ g++ 编译器的疑问,vc++能通过,g++报错。

2012-10-23 
求助~~~ g++ 编译器的疑问,vc++能通过,g++报错。。。。g++编译器是不是不允许把类型参数传给vector呢?具体情况

求助~~~ g++ 编译器的疑问,vc++能通过,g++报错。。。。
g++编译器是不是不允许把类型参数传给vector呢?
具体情况如下,定义一个模版函数:

template <typename Iterator, typename ElemType>
vector<ElemType> sub_vec(const Iterator first, const Iterator last, const ElemType &val)
{
vector<ElemType> vec(first, last);
sort(vec.begin(), vec.end());
vector<ElemType>::iterator it = find_if(vec.begin(), vec.end(), bind2nd(greater<ElemType>(), val));
vec.erase(vec.begin(), it);
return vec;
}

用类型参数直接定义vector<ElemType>,g++就会报错,但可以在vc编译器可下通过
g++的错误信息
as.cpp: In function `std::vector<ElemType, std::allocator<_T2> > sub_vec(Iterator, Iterator, const ElemType&)':
as.cpp:22: error: expected `;' before "it"
as.cpp:23: error: `it' was not declared in this scope
as.cpp: In function `std::vector<ElemType, std::allocator<_T2> > sub_vec(Iterator, Iterator, const ElemType&) [with Iterator = __gnu_cx
x::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, ElemType = int]':
as.cpp:52: instantiated from here
as.cpp:22: error: dependent-name ` std::vector<ElemType,std::allocator<_T2> >::iterator' is parsed as a non-type, but instantiation yie
lds a type
as.cpp:22: note: say `typename std::vector<ElemType,std::allocator<_T2> >::iterator' if a type is meant




[解决办法]
唉,基础不过关啊

热点排行