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

前端 未结 8 1295
无人及你
无人及你 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:22

    I had this issue programing a class in c++, and i solved it by doing the following:

    Line that produced the same error mentioned here before:

    findAndDrawContoursFrame(cv::Mat&,cv::Mat&,std::vector<std::vector<cv::Point»&);
    

    Line that passed through GCC Cross Compiler and Worked:

    findAndDrawContoursFrame(cv::Mat&,cv::Mat&,std::vector< std::vector<cv::Point> >&);
    

    For me it was just an error on the interpretation of the statement.

    0 讨论(0)
  • 2020-11-28 11:23

    Sometimes you want it to be >>. Consider

    boost::array<int, 1024>>2> x;
    

    In C++03 this successfully parses and creates an array of size 256.

    0 讨论(0)
  • 2020-11-28 11:23

    It won't ever be ambiguous. This is proven by the fact that in C++0x you don't have to write a space between closing template >s any more.

    The thing is that the compilers would prefer to tokenize the input as context-independently as possible. Since C++ is not a context independent language anyway, adding just this one special case isn't going to make things particularly harder.

    0 讨论(0)
  • 2020-11-28 11:24

    In the current standard, tokenization is greedy, so >> will be processed as a single token, in the same way that a +++ b will be parsed as a ++ + b. This has changed and the new standard. While it requires more work from the compiler implementors, it was deemed that overall it is worth it (and some major compilers already implement that as an extension anyway).

    0 讨论(0)
  • 2020-11-28 11:24

    It depends on the compiler. Visual Studio does not mandate this i.e. both works while g++ produces an error. I think that this depends on the compiler implementation.

    0 讨论(0)
  • 2020-11-28 11:37

    Stream Syntax

    cin >> var;

    Vs

    Nested Template Syntax

    For<Bar<Barz>>

    First phase of Compiler, lexical analyser will not be able to recognise.

    0 讨论(0)
提交回复
热议问题