Visual C ++ C2143 error: syntax error: missing ')' before 'constant'

I get an error in Visual C ++ that gives me a very difficult time.

Error: error c2143: syntax error: missing ')' before 'constant'

My line of code:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth); 

I have #include at the beginning of the file that the floor (double) function should define.

A bit more explanation of the variables.

double depth is a member variable of the class in which this string can be found.
int i is the index value. double t is an extra value.

What they do is really inconsequential, but I wanted to clarify that all three are already defined as variables of basic types.

I passed the test and confirmed that all parentheses match. I don’t understand what the “constant” referenced by the compiler is. Any ideas?

+3
source share
6 answers

I'm not quite sure that this is the same error as the compiler, but you have to put a "*" before the second "2" so that this:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth);

Becomes as follows:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) * 2 * depth);
+6
source

Other posters showed you the actual error in the instructions, but please divide it into several subqueries, which more clearly show what you are trying to do mathematically, because this function will cause you headaches in the future if you do not!

+6
source
coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) (the problem is here) 2 * depth);
+5

, , .

​​ , , , , .

:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth);

:

firsthalf = (1 - (2 * depth));
secondhalf = ((t - floor( t + 0.5 ) + 1 ) 2 * depth);   // Error appears on this line
coefficient[i] = firsthalf + secondhalf;

.

:

exprA = (t - floor( t + 0.5 ) + 1 );
exprB = exprA * 2;
exprC = exprB * depth;   // Hmm.... this all worked.  Start putting it back together.
secondhalf = exprC;

:

exprA = (( MY_TEST_CONSTANT ) 2 * depth);   // Error now becomes obvious.
+2

[i] = (1 - ( 2 *)) + ((t - (t + 0,5) + 1) 2 ( 2?) * );

+1

. , ​​ .

+1

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


All Articles