首页 > 编程语言 > 详细

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

时间:2014-03-13 12:20:30      阅读:531      评论:0      收藏:0      [点我收藏+]
#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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!