そのため、シェイプクラスのコンストラクターに渡されるchar *にメモリを割り当てるのに問題があり、「malloc:*オブジェクト0x1001000e0のエラー:解放されるポインターが割り当てられませんでした」というエラーが発生し続けます。私はグーグルをたくさんしました、そして私は答えを見つけます、しかしそれらは意味がありません、私は何が悪いのか理解していません。shapeNameは、shapeの保護されたchar*メンバーです。正方形は形の子です。誰かが何が悪いのか説明していただければ幸いです。ありがとうございます。
私のコンストラクター:
Shape::Shape(Point* origin,char* name) {
this->origin = origin;
this->shapeName = (char*) new char(strlen(name)+1);
strcpy(shapeName, name);
}
私のデストラクタ:
Shape::~Shape() {
delete shapeName;
delete origin;
}
スクエアのコンストラクター:
Square::Square(Point* origin, char* squareName, double side)
: Shape(origin, squareName){
side_a = side;
}
私の電話:
Square s(new Point(5,7),"Square - S", 12);
s.display();
cout << "The area of " << s.getName() << " is: " << s.area() << endl;
cout << "The perimeter of " << s.getName() << " is: " << s.perimeter();