0

I need to build an array to contain objects. However, it does not work and I could not find out the error myself. Please help

 # include "CRegistration.h" //My object class

SKIP MANY LINES

    public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
        array<CRegistration^> ^CregArray = gcnew array<CRegistration^>(100);
        record_number = 0;
    }


private: System::Void MyAdd_Click(System::Object^  sender, System::EventArgs^  e) {
         Form2^ myForm2 = gcnew Form2();
         if (myForm2->ShowDialog()==System::Windows::Forms::DialogResult::OK) {
            record_number = record_number + 1;
            CRegistration^ Creg = gcnew CRegistration(System::Convert::ToString(record_number),myForm2->TempReg[0],myForm2->TempReg[1],myForm2->TempReg[2],myForm2->TempReg[3]);
            CregArray[record_number-1]  = Creg;



         }
     }
};

1 Answer 1

1

change line

array<CRegistration^> ^CregArray = gcnew array<CRegistration^>(100);    

to

CregArray =  gcnew array<CRegistration^>(100);    

add field declaration:

Form1(void) 
{ 
   ..
} 

array<CRegistration^> ^CregArray; 

private: System::Void MyAdd_Click(System::Object^  sender, System::EventArgs^  e) { 
    ..
 } 
Sign up to request clarification or add additional context in comments.

1 Comment

Error 1 error C2065: 'CregArray' : undeclared identifier c:\users\marco\desktop\cs351\hw3\project3\Form1.h 28 1 Project3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.