为矩形类定义复制构造函数

学习 时间:2026-04-02 17:34:58 阅读:6937
为矩形类定义复制构造函数在rect.h 头文件中的类rect定义中加入以下代码:Rectangle(Rectangle & rec);在rect.cpp文件中添加以下代码:Rectangle::Rectangle(Rectangle & rec){ left=rec.left;top=rec.top;right=rec.right ; bottom=rec.bottom ;}//复制构造函数在main( )函数中添加以下代码:Rectangle rect2(rect1);cout < < ”由复制构造函数生成的rect2:”

最佳回答

健壮的老虎

独特的柚子

2026-04-02 17:34:58

默认构造函数 是没有形参的。

最新回答共有2条回答

  • 稳重的小懒猪
    回复
    2026-04-02 17:34:58

    默认构造函数 是没有形参的。

上一篇 Look!The boy is playing-----the tree.His mother is looking a

下一篇 房间用什么消毒