C++赋值运算符、函数调用运算符、下标运算符(“=”、“()”、“[]”)重载

#include <iostream>
#include <assert.h>
#include <string.h>

using namespace std;

class cstring
{
public:
    cstring(char *str="");
    cstring(const cstring &str);

cstring operator+(const cstring &str);
    //赋值运算符只能用成员函数重载,不能被继承,用户自己不重载系统会默认冲在一个(但不一定能满足要求)
    cstring &operator=(const cstring &str);
    //重载函数调用运算符,只能用成员函数
    int operator()();
    //重载下标运算符,只能用成员函数
    char operator[](int i);
    void print(void);

private:
    char *m_pstr;
    int m_isize;
};

上一篇:第1章 shell编程概述


下一篇:windows下mongodb设置用户名密码&用python连接