char and constructors in c ++

0

I need a constructor for a class that has char vectors as attributes, like this:

class Anthem {
    private:
        int Id;
        char Name[50];
        char Country[50];
        int Year;
        char Composer[30];
        char Historic[200];
    public:
        Anthem(int id, char name[50], char country[50], int year, char 
composer[30], char historic[200]);
        ~Anthem();
}

But I do not know how to stay in the de facto builder, I did so:

Anthem::Anthem(int id, char* name, char* country, int year, char* composer, 
char* historic) { // @suppress("Class members should be properly initialized")
    Id = id;
    Name = name;
    Country = country;
    Year = year;
    Composer = composer;
    Historic = historic;
}

But it's not right, how should I do it?

    
asked by anonymous 30.05.2018 / 20:04

1 answer

0

You need to use

Name[] = name;
assert( strlen( Name) < sizeof( name) );
strcpy( name, Name );

instead of

Name = name;

See here ;

    
30.05.2018 / 20:32