问题
The following code works under gcc versions 2.9 through 4.4 but not version 4.5:
struct Pass {
};
int main(void){
Pass **passes = new ( Pass (*[ 10 ]) );
}
The specific error message with gcc 4.5 is:
prob.cc: In function ‘int main()’:
prob.cc:6:31: warning: lambda expressions only available with -std=c++0x or -std=gnu++0x
prob.cc:6:38: error: no matching function for call to ‘Pass::Pass(void (&)())’
prob.cc:2:1: note: candidates are: Pass::Pass()
prob.cc:2:1: note: Pass::Pass(const Pass&)
Adding the requested flag silences the initial warning but does not fix the issue. Could someone explain how to fix this? This is from some obscure piece of C++ code I'm maintaining and I know only a limited amount of C++.
回答1:
Pass** passes = new Pass*[10];
回答2:
I think this will do it:
typedef Pass * PassPtr;
Pass **passes = new PassPtr[10];
回答3:
I don't understand why you are trying to wrap it so much.
Pass** passes = new Pass*[10];
Does that not work?
回答4:
The extraneous parentheses you are using is now making it seem to the compiler like you are passing a constructor of Pass a lambda as a parameter. Lambdas are a new addition in C++0x, which would be why this error only cropped up in the new compiler. You can fix it by using Pass** passes = new Pass*[10];
instead.
来源:https://stackoverflow.com/questions/4925647/c-array-creation-problem-specific-to-gcc-4-5