运算符重载之数组实例的应用

本文探讨了运算符重载在处理数组时的具体应用,通过代码示例和注释详细阐述了如何实现和理解这一技术。
摘要由CSDN通过智能技术生成

关于运算符重载的各种应用,具体看代码注释

 

MyString.h

#pragma once
#include<iostream>
using namespace std;

//c中没有字符串,字符串类(c风格的字符串)
//空串 ""

class MyString
{
	friend ostream& operator<<(ostream &out,MyString &s);  //这里是函数运算符重载,之所以用全局而不是用成员函数,是因为第一个操作数无法通过this指针隐士传递,第一个操作数其类型是ostream
	friend istream& operator>>(istream& in,MyString &s);

public:
	MyString(int len = 0);
	MyString(const char* p);
	MyString(const MyString& s);
	~MyString();

public:  //重载=号运算符
	MyString& operator=(const char* p);   //第一个操作数通过this指针隐式传递
	MyString& operator=(const MyString& s);
	char& operator[](int index);

public:   //重载 == !==
	bool operator==(const char *p) const;
	bool operator==(const MyString &s) const;
	bool operator!=(const char *p) const;
	bool operator!=(const MyString& s) const;

public:
	int op
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值