Note
Kailangan ng pahintulot para ma-access ang page na ito. Maaari mong subukang mag-sign in o magpalit ng mga direktoryo.
Ang pag-access sa pahinang ito ay nangangailangan ng pahintulot. Maaari mong subukang baguhin ang mga direktoryo.
'var' : l-value use of initonly data member is not allowed directly within a parallel region in class 'class'
Remarks
An initonly (C++/CLI) data member cannot be initialized inside that part of a constructor that is in a parallel region. This is because the compiler does an internal relocation of that code, such that, it is effectively no longer part of the constructor.
To resolve, initialize the initonly data member in the constructor, but outside the parallel region.
Example
The following example generates C3899.
// C3899.cpp
// compile with: /clr /openmp
#include <omp.h>
public ref struct R {
initonly int x;
R() {
x = omp_get_thread_num() + 1000; // OK
#pragma omp parallel num_threads(5)
{
// cannot assign to 'x' here
x = omp_get_thread_num() + 1000; // C3899
System::Console::WriteLine("thread {0}", omp_get_thread_num());
}
x = omp_get_thread_num() + 1000; // OK
}
};
int main() {
R^ r = gcnew R;
System::Console::WriteLine(r->x);
}