Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Commonmark migration
Source Link

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

 

— as the initializer in a variable definition (8.5)

 

— as the initializer in a new expression (5.3.4)

 

— in a return statement (6.6.3)

 

....

It does not list the conditional operator. As others have said an alternative is to use an if statement. Although as James points out this may not be the ideal substitution, so if you feel that the conditional operator works better in your context then as James suggests just use the following:

arrnode.push_back( arr[j] == '(' ? node( 1, 1 ) : node( -1, -1 ) ); 

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

 

— as the initializer in a variable definition (8.5)

 

— as the initializer in a new expression (5.3.4)

 

— in a return statement (6.6.3)

 

....

It does not list the conditional operator. As others have said an alternative is to use an if statement. Although as James points out this may not be the ideal substitution, so if you feel that the conditional operator works better in your context then as James suggests just use the following:

arrnode.push_back( arr[j] == '(' ? node( 1, 1 ) : node( -1, -1 ) ); 

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

— as the initializer in a variable definition (8.5)

— as the initializer in a new expression (5.3.4)

— in a return statement (6.6.3)

....

It does not list the conditional operator. As others have said an alternative is to use an if statement. Although as James points out this may not be the ideal substitution, so if you feel that the conditional operator works better in your context then as James suggests just use the following:

arrnode.push_back( arr[j] == '(' ? node( 1, 1 ) : node( -1, -1 ) ); 
added 240 characters in body
Source Link
Shafik Yaghmour
  • 159.8k
  • 44
  • 466
  • 778

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

— as the initializer in a variable definition (8.5)

— as the initializer in a new expression (5.3.4)

— in a return statement (6.6.3)

....

It does not list the conditional operator. As others pointed out usinghave said an alternative is to use an if statement would. Although as James points out this may not be a muchthe ideal substitution, so if you feel that the conditional operator works better way to go about this.in your context then as James suggests just use the following:

arrnode.push_back( arr[j] == '(' ? node( 1, 1 ) : node( -1, -1 ) ); 

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

— as the initializer in a variable definition (8.5)

— as the initializer in a new expression (5.3.4)

— in a return statement (6.6.3)

....

It does not list the conditional operator. As others pointed out using an if statement would be a much better way to go about this.

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

— as the initializer in a variable definition (8.5)

— as the initializer in a new expression (5.3.4)

— in a return statement (6.6.3)

....

It does not list the conditional operator. As others have said an alternative is to use an if statement. Although as James points out this may not be the ideal substitution, so if you feel that the conditional operator works better in your context then as James suggests just use the following:

arrnode.push_back( arr[j] == '(' ? node( 1, 1 ) : node( -1, -1 ) ); 
Source Link
Shafik Yaghmour
  • 159.8k
  • 44
  • 466
  • 778

So using gcc the error you see will look something like so:

error: expected primary-expression before ‘{’ token 

It is expecting an expression but {}s are not an expression, they are just usable for list initialization in some places as specified by section 8.5.4 of the draft standard, which says:

... List-initialization can be used

— as the initializer in a variable definition (8.5)

— as the initializer in a new expression (5.3.4)

— in a return statement (6.6.3)

....

It does not list the conditional operator. As others pointed out using an if statement would be a much better way to go about this.