| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 372 人关注过本帖
标题:很乱但觉得很有用的东西
只看楼主 加入收藏
zhubenben
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-3-28
收藏
 问题点数:0 回复次数:0 
很乱但觉得很有用的东西

这个是根据别人的帖子改的
#include <iostream>

using namespace std;

class Sample
{
protected:
int x;
public:
Sample() { x=0; }
Sample(int val) { x=val; }
Sample(Sample& st)
{
x = st.x;
cout<< "Sample引用" <<endl;
}
void operator++(int) { x++; }
void operator=(Sample st1)
{
x = st1.x;
cout<< "sample=" <<endl;
}
virtual void disp() const
{
cout<<"x="<< x << endl;
}
friend ostream& operator<<(ostream& os, const Sample& kk)
{
os<< kk.x;
return os;
}
};


class Derived:public Sample
{
int y;
public:
Derived():Sample(){ y=0; }
Derived(int val1,int val2):Sample(val1){ y=val2; }
Derived(Derived& de):Sample(de)
{
y = de.y;
cout<< "deribed&" <<endl;
}
void operator--(int){ x--;y--;}
void operator=(Derived de1)
{
Sample::operator=(de1);
y = de1.y;
cout<< "deribed=" <<endl;
}
friend ostream& operator<<(ostream& os, const Derived& k)
{
os<< k.x << " " <<k.y;
return os;
}
void aaa(Derived de2)
{
cout<< "传值" <<endl;
}
void aaaa(Derived& de3)
{
cout<< "引用" <<endl;
}
virtual void disp() const
{
cout<<"x="<< x <<" y=" << y << endl;
}
};


int main ()
{
Derived d(3,5);
Derived a(d);
Derived c(6,10);
Derived e = c;
Sample aa(100);
d = c;
d.disp();
cout<< "****************************" <<endl;
d.aaa(c);
cout<< "****************************" <<endl;
d.aaaa(c);
cout<< "****************************" <<endl;
cout<< d <<endl;
cout<< "****************************" <<endl;
//Sample&p = aa;
//cout<< p <<endl;
Sample&p = c;
p.disp();
/*d++;
d.disp ();
d--;
d--;
d.disp(); */
return 0;
}

2006-12-15 10:30
快速回复:很乱但觉得很有用的东西
数据加载中...
 
   



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

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