Start New Discussion within our Software Development Community

Hello. I have a problem with one part of my homework. I'm not exactly sure how to say this in English. I want the constructor to build an object and assign string values to attribute1 and attribute2.

I'm only posting the relevant part of my code. My class can be reduced to this:

Compiler used: Borland 5.02

class something
{
   public:
      char attribute1[25];
      char attribute2[25];
      donkey(char a, char b) : attribute1(a), attribute2(b) {}
      donkey(){}
};

Then, I store information about objects in an array.

array[1] = new something("a","bb");
array[2] = new something("ccc","dd");

Problem is within constructors. I end up with different compiler errors, which I can't seem to fix. Depending on how I write the constructor, I end up with errors "can't convert char* to char ", "can't convert char to char[]" etc.

Shedding some light is appreciated.

You could do this

class something
{
   public:
      char attribute1[25];
      char attribute2[25];
      donkey(char* a, char* b)
      {
          strcpy(attribute1,a);
          strcpy(attribute2,b);
      }
      donkey(){}
};
This question has already been answered. Start a new discussion instead.