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

时间:2014-03-13 12:20:30   收藏:0   阅读:538
#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;
};

C++赋值运算符、函数调用运算符、下标运算符(“=”、“()”、“[]”)重载,布布扣,bubuko.com

原文:http://www.cnblogs.com/de0319gh/p/3597636.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!