C++ 继承 002:继承自string的MyString 004:编程填空:统计动物数量

这篇博客探讨了两个C++主题:一是如何继承自`std::string`创建`MyString`类,涉及无参、有参及复制构造函数的实现;二是编程填空题,要求完善代码以统计不同动物的数量,但指出在没有使用虚函数的情况下,猫的数量可能不准确,暗示了后续课程将讲解虚函数的重要性。
摘要由CSDN通过智能技术生成

002:继承自string的MyString

描述
程序填空,输出指定结果

#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class MyString:public string
{
   
// 在此处补充你的代码
};


int main()
{
   
	MyString s1("abcd-"),s2,s3("efgh-"),s4(s1);
	MyString SArray[4] = {
   "big","me","about","take"};
	cout << "1. " << s1 << s2 << s3<< s4<< endl;
	s4 = s3;
	s3 = s1 + s3;
	cout << "2. " << s1 << endl;
	cout << "3. " << s2 << endl;
	cout << "4. " << s3 << endl;
	cout << "5. " << s4 << endl;
	cout << "6. " << s1[2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值