The problem of creating a C ++ array specific to gcc 4.5

The following code works in gcc versions 2.9-4.4, but not version 4.5:

 struct Pass {
 };

 int main(void){
 Pass **passes = new ( Pass (*[ 10 ]) );
 }

Specific error message with gcc 4.5:

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 ignores the initial warning, but does not fix the problem. Can someone explain how to fix this? This is from some obscure part of the C ++ code that I support, and I only know a limited amount of C ++.

+3
source share
4 answers
Pass** passes = new Pass*[10];
+5
source

I think this will do:

typedef Pass * PassPtr;
Pass **passes = new PassPtr[10];
+3
source

, .

Pass** passes = new Pass*[10];

?

+2

The extraneous brackets you use now lead to the compiler, as if you were passing the Pass lambda constructor as a parameter. Lambdas is a new addition in C ++ 0x, and that is why this error appeared only in the new compiler. You can fix it using Pass** passes = new Pass*[10];.

+1
source

Source: https://habr.com/ru/post/1790533/


All Articles