Hello!
Please help me correct the error:
error C2230: 'GenerateRandomHReal': it doesn’t mean an aggregate
I am writing a project based on the Windows Form Application. NET in Microsoft Visual C ++. NET 2003. The program logic is implemented directly in the class Form file Form1.h (I understand, not very correctly, but these are details). The program at the touch of a button fills the matrix with random numbers and performs some calculations. There is a third-party math library written in non-managed C ++. This library describes the data type (high accuracy) HReal. It turns out that, as it were, in managed C ++ (__gc class Form1), a function method is used that takes arguments and returns the value of an unmanaged HReal type. So this error is issued. But how to fix it?
I read, stumbled upon such concepts as: 1) the template class gcroot <TYPE>, the structure of GCHandle; 2) writing a wrappera for a class; 3) use of # pragma managed and # pragma unmanaged directives to combine managed and unmanaged C ++ in one module.
Tell me how to fix, maybe using the above concepts? Or am I looking in the wrong direction? Tell me please! Thank!
#include <string.h> #include <cstringt.h> #include <afxwin.h> #using <mscorlib.dll> #pragma once namespace SolveSLAU { using namespace std; using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public __gc class Form1 : public System::Windows::Forms::Form { // Глобальные переменные private: bool IsButton1Pressed; bool IsMatrixSet; // Флаг: "Матрица уже инициализирована?" HReal **A01, **A02, *B01, *B02, *X1_2, *X2_1; double Eps; // Точность расчетов Эпсилон int m1, m2, n0; int MantissPrecision; // Точность мантиссы private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { int n = 0, i,j; HReal ** A1, ** A2, *X1; HReal * B1, * B2, *X2; HReal alfa_0, alfa_1; CString myStr1(""); CString myStr2(""); CString myStr3(""); CString myStr0(""); CString myspace(" "); MantissPrecision = System::Int32::Parse(this->textBox1->Text); Eps = System::Double::Parse(this->textBox2->Text); ***** this->listBox6->Items->Add(System::Convert::ToString(myStr0)); X1[i] = GenerateRandomHReal(alfa_0, alfa_1, MantissPrecision); X1_2[i] = GenerateRandomHReal(alfa_0, alfa_1, MantissPrecision); myStr0.Format(_T("%lf\n"), X1[i] ); this->listBox2->Items->Add(System::Convert::ToString(myStr0)); X2[i] = GenerateRandomHReal(alfa_0, alfa_1, MantissPrecision); X2_1[i] = GenerateRandomHReal(alfa_0, alfa_1, MantissPrecision); myStr0.Format(_T("%lf\n"), X2[i] ); this->listBox5->Items->Add(System::Convert::ToString(myStr0)); } } else { // -------------------- генератор ---------------- private: gcroot<HReal> GenerateRandomHReal(const gcroot<HReal> &a, const gcroot<HReal> &b, int MantissPrecision) // [a,b] - диапазон { CString s = "0.", s1; int j; for (int i = 0; i < MantissPrecision; i++) { j = rand() % 10; s1.Format("%i", j); s += s1; } HReal result(s); return a + result * (b - a); }