我正在尝试将对象添加到对象列表中。但是我遇到了几个问题。
我有2个班级:
element.h展开
#pragma once
#include "LinePiece.h"
using namespace System::Collections::Generic;
ref class Element
{
public:
Element();
//properties
System::String^ ON; //order nummer
System::String^ MO; //order merk
System::String^ SN; //element nummer
System::String^ RS; //element afwerking
System::String^ OW; //wapeningspatroon
System::String^ CN; //element calculation number
int el_length; //element lengte
int el_width; //element hoogte
int el_beginX; //element beginpunt
int el_concrete_height; //element hoogte beton
int el_iso_height; //element isolatie hoogte
System::String^ el_weight; //element gewicht
List<LinePiece^>^ listLinePieces; //lijst met contouren
};
和我的第二堂课:LinePiece.h
#pragma once
ref class LinePiece
{
private :
System::String^ Type;
int ElementNr;
int Status;
int X, Y, X2, Y2;
int Diameter;
System::String^ Text;
public:
LinePiece();
//Constructor CO
LinePiece(System::String^ a_type, int a_ElementNr, int a_Status, int a_x, int a_y)
{
Type = a_type;
ElementNr = a_ElementNr;
Status = a_Status;
X = a_x;
Y = a_y;
}
//Constructor LN met tekst
LinePiece(System::String^ a_type, int a_ElementNr, int a_Status, int a_x, int a_y, int a_x2, int a_y2, System::String^ a_text)
{
Type = a_type;
ElementNr = a_ElementNr;
Status = a_Status;
X = a_x;
Y = a_y;
X2 = a_x2;
Y2 = a_y2;
Text = a_text;
}
和我的上一个文件我有ReadPlotFile.h,我填写了我的列表。
List<Element^>^ ReadPlotFile::GetElementInfo(List<String^>^ a_FileBuffer)
{
List<Element^>^ ElementList = gcnew List<Element^>;
List<LinePiece^>^ LinePieceList = gcnew List<LinePiece^>;
Type = "LN";
EleNr = System::Convert::ToInt32(ElementNumber);
Status = 0;
Line = "BO 55041 0 61920 0"; // a line out of a file
X1 = System::Convert::ToInt32(Line->Substring(3, 9));
Y1 = System::Convert::ToInt32(Line->Substring(12, 9));
X2 = System::Convert::ToInt32(Line->Substring(21, 9));
Y2 = System::Convert::ToInt32(Line->Substring(30, 9));
LinePiece lpObject(Type, EleNr, Status, X1, Y1, X2, Y2);
LinePieceList->Add(lpObject); // ERROR HERE
}
我知道错误是抱怨在我的列表中添加LinePiece
对象(因为我的列表是LinePiece^
)。
错误:C2664'void System :: Collections :: GenericList :: Add(LinePiece ^)':无法将参数1从'LinePiece转换为Linepiece ^'
但是当我删除列表中的^
时。 (比如:List<LinePiece>^ LinePieceList<LinePiece>;
它给出了以下错误:“LinePiece”不是有效的通用参数。
如何解决此问题并将LinePiece对象添加到列表中?