0

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?

4
  • I see this construct with class foo { public: struct foo(){} }; for the first time. Why struct? Is this supposed to be just a plain constructor? Commented Aug 27, 2015 at 14:35
  • I guess the question to ask you is "do you know why the error occurs?". Depending on your answer, you will get more focused solutions to the problem. Commented Aug 27, 2015 at 14:35
  • Ye I'm pretty new to the C++ programming. But I understand tehe problem now thanks to Maksim Solovjov Commented Aug 28, 2015 at 6:00
  • @Bart Well, the answers may be adequate. However the reason why I asked the question as to whether you know the reason why is that a default constructor may not be what you wanted to have, and to add one would go against your original design (maybe the object has no meaning if it is default constructed). If that is the case, there are other ways of achieving the goal without defining a default constructor. Commented Aug 28, 2015 at 17:27

2 Answers 2

2

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
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I've been struggling with this problem for hours, yet it's simply resolved. I guess I still have to get used to C++ programming. I'm used to C# but still the differences aren't that big.
1

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.

Comments

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.