I am new to visual C++. I wrote my class, but it has error
Error 1 error C3845: ‘CRegistration::list1’: only static data members can be initialized inside a ref class or value type c:\users\marco\desktop\cs351\hw3\project3\CRegistration.h 44 1 Project3
I understand the compiler has said what the error is. However, I don’t understand what it means. The following is my code
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::Collections::Generic;
public ref class CRegistration
{
public:
CRegistration(void){
ClickBoxRecord = 0;
ClickBoxRecord = 0;
};//end constructor
void SetRadioRecord(int flag){ RadioRecordRecord = flag; }
void SetClickBoxRecord(int flag){ ClickBoxRecord = flag; }
int GetRadioRecordRecord(){return RadioRecordRecord}
int GetClickBoxRecord(){return ClickBoxRecord}
protected:
private:
int RadioRecordRecord;
int ClickBoxRecord;
LinkedList< int > list1 = gcnew LinkedList< int >();
LinkedList< String^ > ^list2 = gcnew LinkedList< String^ >();
LinkedList< String^ > ^list3 = gcnew LinkedList< String^ >();
LinkedList< String^ > ^list4 = gcnew LinkedList< String^ >();
LinkedList< String^ > ^list5 = gcnew LinkedList< String^ >();
};//end ref class
Are you trying to learn C++ or are you trying to learn CLI?
P.S.
The problem is your inline initialization of non-static members list1 through list5. In C++ initialization of non-static members is done in an initializer list or the body of a constructor normally. In C++ we generally use the stack as much as possible and only use the heap when we have to as memory management is important.