#include<cstring> #include <iostream> #include <new> #include<string> using namespace std; class Printed_edition { protected: static int N; char name[25]; int page; char type[25]; int i; Printed_edition* temp; public: Printed_edition(void) { N++; cout << "Counstructor without parameters!base!" << endl; page = 0; temp = this; } Printed_edition(const char Name[], const char Type[], int Value) { SetName(Name); SetType(Type); page = Value; } virtual ~Printed_edition(void) { cout << "Destructor" << endl; } virtual void show() { N = 0; for (i = 0; i < N; i++) { cout << temp->GetName() << endl; } } void SetName(const char Value[]) { strcpy_s(name, Value); } void SetType(const char Value[]) { strcpy_s(type, Value); } void SetPage(int Value) { page = Value; } char* GetName() { return name; } char* GetType() { return type; } int GetPage() { return page; } }; class magazine : virtual public Printed_edition { magazine() { cout << "Counstructo without parameters" << endl; page = 0; } magazine(const char Name[],const char Type[], int Page) { strcpy_s(name, Name); strcpy_s(type, Type); page = Page; } magazine(const magazine& a) { cout << "Copying Constuctor" << endl; name = new char[strlen(a.name) + 1]; strcpy_s(name, a.name); type = new char[strlen(a.type) + 1]; strcpy_s(type, a.type); page = a.page; } virtual ~magazine() { cout << "Destructor" << endl; } }; class book : virtual public Printed_edition { private: char genre[25]; public: book() { cout << "Constructor without parameters" << endl; page = 0; } book(const char Name[], const char Type[], int Page, const char Genre[]) { strcpy_s(name, Name); strcpy_s(type, Type); page = Page; strcpy_s(genre, Genre); } book(const book& a) { cout << "Copying Constructor" << endl; name = new char[strlen(a.name) + 1]; strcpy_s(name, a.name); page = a.page; type = new char[strlen(a.type) + 1]; strcpy_s(type, a.type); genre = new char[strlen(a.genre) + 1]; strcpy_s(genre, a.genre); } ~book() { cout << "Destructor" << endl; } void show() { for (i = 0; i < N; i++) { cout << temp->GetName() << endl; } } void SetGenre(const char GENRE[]) { strcpy_s(genre, GENRE); } char* GetGenre() { return genre; } }; class learning_book : virtual public Printed_edition, book { private: char lessontype[25]; public: learning_book() { cout << "Constructor wp" << endl; page = 0; } learning_book(const char Name[], const char Type[], int Page, const char Lessontype[]) { cout << "Constructor with parameters" << endl; strcpy_s(name, Name); strcpy_s(type, Type); page = Page; SetLesson(Lessontype); } learning_book(const learning_book& a) { cout << "Copying Constructor" << endl; name = new char[strlen(a.name) + 1]; strcpy_s(name, a.name); page = a.page; type = new char[strlen(a.type) + 1]; strcpy_s(type, a.type); lessontype = new char[strlen(a.lessontype) + 1]; strcpy_s(lessontype, a.lessontype); } ~learning_book() { cout << "Destructor" << endl; } /*void show() { if (i = 0; i < N; i++) { cout << temp->GetName() << endl; } }*/ void SetLesson(const char LT[]) { strcpy_s(lessontype, LT); } char GetLessonType() { return lessontype[25]; } }; int main() { // N = 0; magazine b1("Tall", "magazine", 12); system("pause"); } 
  • one
    If you allocate memory with new , then you need to store pointers in the class, not arrays. - HolyBlackCat

1 answer 1

Well, you can not assign something to an array in C / C ++. How do you even imagine it?

 char name[25]; name = new char[50]; 

name is a declared array, which is always that array. Very roughly - as the number 2 is the number itself, and assign 2 = 5; is impossible.

Work with pointers -

 char * name;