代码之家  ›  专栏  ›  技术社区  ›  LarryF

GCC下的模板函数

  •  -2
  • LarryF  · 技术社区  · 17 年前

    this .

    有人能告诉我为什么它不能在GCC下编译吗?MSVC6和VS2008都将编译它,甚至没有任何警告。

    代码。。。

    #include <iostream>
    #include <vector>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    template <typename T>
    T range(vector<T> &v)
    {
       vector<T>::iterator i = v.begin();
    

    在最后一行抛出错误,应为;在我之前。

    我需要打字吗?

    1 回复  |  直到 9 年前
        1
  •  3
  •   moonshadow    17 年前

    编译器没有足够的知识将vector::iterator解析为此时的类型。使用typename关键字给出提示:

    typename vector<T>::iterator i = v.begin();