Template within template: why “`>>' should be `> >' within a nested template argument list”

前端 未结 8 1404
无人及你
无人及你 2020-11-28 10:40

I know that when we are using template inside another template, we should write it like this:

vector > s;

and if we wr

8条回答
  •  感动是毒
    2020-11-28 11:43

    Avoid this error by setting an appropriate C++ dialect. For example, with gcc 4.9 the following file does not compile with g++:

    #include 
    #include 
    
    int main()
    {
        using namespace std;
        vector> v; // compile error!
        return 0;
    }
    

    Let's get to the bottom of things:

    #include 
    
    int main()
    {
        std::cout << __cplusplus << std::endl;
        return 0;
    }
    

    Compiled with just g++ test.cpp this code prints 199711. Although gcc 4.9 was released in 2014 the default C++ dialect is C++98 with GNU extensions. C++98 requires us to write vector >. If you like vector> more compile with -std=c++11 or -std=gnu++11.

提交回复
热议问题