| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 592 人关注过本帖
标题:新人求解vc++书上二元重载
只看楼主 加入收藏
leekey
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-11-7
结帖率:0
收藏
 问题点数:0 回复次数:0 
新人求解vc++书上二元重载
#include <iostream>
using namespace std;
class IntArray
{
private:
    int* pInt;
    int nCount;
public:
    IntArray(int count){
        nCout=count
        pInt=new int[nCount];
    }
    ~IntArray(){
        delete[]pInt;
        pInt=NULL;
                                            }
    }
    int operator[](int index) const{
        if(index<0 || index>=nCout)
            return 0;
        return pInt[index];
    }
    void SetAt(int index,int value){
        if(index<0 || index>=nCount)
            return;
        pInt[index]=value;
    }
    int GetLength(){
        return nCount;
    }
};
int main()
{
    IntArray arr(3);
    arr.SetAt(0,12);
    arr.SetAt(1,45);
    arr.SetAt(2,80);
    for(int i=0;i<<arr.GetLength();i++0
    {
        cout<<"第"<<i+1<<"个元素"<<arr[i]<<endl;
    }
    cout<<endl;
    return 0;
}
按书上打的二元重载 这能用于什么
搜索更多相关主题的帖子: private include public return 
2011-11-07 20:21
快速回复:新人求解vc++书上二元重载
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017066 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved