Bart
Bart

Reputation: 767

issue with object array C++ (Embarcadero)

I've got a element class with a struct and I would like to place some objects in the array. My class:

class element
{
public:
//properties
AnsiString ON;          //order nummer
AnsiString MO;          //order merk
AnsiString SN;          //element nummer
AnsiString RS;          //element afwerking
AnsiString OW;          //wapeningspatroon
AnsiString 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
int el_weight;          //element gewicht

//struct om objecten aan te maken
struct element(AnsiString a_ON, AnsiString a_MO, AnsiString a_SN, AnsiString a_RS, AnsiString a_OW, AnsiString a_CN,
int a_elLength, int a_elWidth, int a_elBeginX, int a_elConcreteHeight, int a_elIsoHeight)
{
    ON = a_ON;
    MO = a_MO;
    SN = a_SN;
    RS = a_RS;
    OW = a_OW;
    CN = a_CN;
    el_length = a_elLength;
    el_width = a_elWidth;
    el_beginX = a_elBeginX;
    el_concrete_height = a_elConcreteHeight;
    el_iso_height = a_elIsoHeight;
};

Anyways there is no problem with this class.

I've got another header file:

DynamicArray<element> ElementArray;

element ElementObject("", "", "", "", "", "", 0, 0, 0, 0, 0,); // just example
ElementArray.set_length(10);
ElementArray[0] = ElementObject;

And this is my error: [bcc32Error] sysdyn.h(689):The problem: E2285 Could not find a match for 'element::element()'

So my question is how can I solve this problem?

Upvotes: 0

Views: 121

Answers (2)

anderas
anderas

Reputation: 5844

The error says that your element class has no default constructor although one is requested. Most likely, the DynamicArray template needs the contained element type to have a default constructor to be able to allocate objects e.g. in the call to set_length(10).

To solve the problem, simply add a default constructor (i.e. element(){...}) to your class and the error should be fixed.

Upvotes: 1

Maksim Solovjov
Maksim Solovjov

Reputation: 3157

When you set_length of the DynamicArray, it populates the array with objects created using a default constructor. For this to happen, element needs to provide one:

class element
{
public:
    element() {}
    // the rest
};

Upvotes: 2

Related Questions