A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Hi @Sid Kraft ,
Thanks for reaching out.
That statement is valid in C++ as long as the left-hand side resolves to a writable scalar value and the other expressions evaluate to numeric values such as float. Because of that, the = operator itself is usually not the real issue.
An error like this means one of the operands is not the type the compiler expects, or the left-hand side is not something that can be assigned to.
If CHMID1, PT1, and VEC1 are std::vector<float> objects, then this pattern should work as expected:
std::vector<float> CHMID1(n);
std::vector<float> PT1(n);
std::vector<float> VEC1(n);
float CHORD1 = 10.0f;
for (std::size_t I = 0; I < n; ++I)
{
CHMID1[I] = PT1[I] + (CHORD1 * VEC1[I]) / 2.0f;
}
The next things I would check are whether CHMID1 is writable and not declared as const, whether I is an integer type used for indexing, and whether CHMID1[I], PT1[I], and VEC1[I] actually resolve to individual numeric values rather than pointers, structs, or nested containers.
It is also worth checking that the vectors have been sized before using operator[], and that I is within range. With std::vector, indexing is only valid when that element already exists.
If any of those expressions are not scalar values, the compiler can produce a misleading error that makes it look like the = operator is the problem when the real issue is the operand type.
If those variables are actually custom vector or math types rather than containers of float, C++ will not perform vector arithmetic automatically unless the necessary operators have been defined for that type. In that case, the calculation may need to be done component by component.
If you can share the declarations of CHMID1, PT1, VEC1, CHORD1, and I, it should be possible to identify the exact cause pretty quickly.
Hope this helps! If my explanation and the information I provided were helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.