Why code using local struct as parameter for STL function does not compile in g++?

后端 未结 2 2084
[愿得一人]
[愿得一人] 2021-02-20 09:47

I have such code which works well:

#include 
#include 

char x[11]= \"ABCDEFGHIJ\";
char y[11];

struct F {
    char operator ()         


        
2条回答
  •  無奈伤痛
    2021-02-20 10:07

    g++ 4.5.1 compiles your code (with -std=c++0x option).

    Your second code sample is ill-formed in C++031 but valid in C++0x

    std::transform is

    template < class InputIterator, class OutputIterator, class UnaryOperator >
      OutputIterator transform ( InputIterator first1, InputIterator last1,
                                 OutputIterator result, UnaryOperator op );
    

    However g++ 4.4 doesn't support local types as template arguments (even with -std=c++0x option] so you get an error.

    1 : A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter. (ISO C++03 §14.3.1.2)

提交回复
热议问题