| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1008 人关注过本帖
标题:[原创]非托管类中的运算符重载
只看楼主 加入收藏
zhangzujin
Rank: 1
等 级:新手上路
帖 子:276
专家分:0
注 册:2005-5-9
收藏
 问题点数:0 回复次数:1 
[原创]非托管类中的运算符重载

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

using namespace std;

class Complex
{
public:
int real;
int imaginary;

Complex( )
{
real=0;
imaginary=0;
}

Complex(int a,int b)
{
real=a;
imaginary=b;
}

Complex operator+(Complex A)
{
real=real+A.real;
imaginary=imaginary+A.imaginary;

return Complex(real,imaginary);
}

void ShowComplex( )
{
cout<<"the real part is:"<<real<<endl;
cout<<"the imaginary part is:"<<imaginary<<endl;
}
};

int _tmain()
{
Complex A(2,3),B(4,5),C;

C=A+B;
C.ShowComplex( );

return 0;
}

搜索更多相关主题的帖子: 运算符 重载 托管 
2006-01-11 21:48
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

using namespace std;

public __gc class Complex
{
private:
int real;
int imaginary;

public:
Complex()
{}

Complex(int a,int b)
{
real=a;
imaginary=b;
}

Complex operator+(Complex A)
{
real=real+A.real;
imaginary=imaginary+A.imaginary;

return Complex(real,imaginary);
}

void ShowComplex( )
{
Concle::Writeline(S"the real part is:", real);
Concle::Writeline(S"the imaginary part is:", imaginary);
}
};

int _tmain()
{
Complex A(2,3),B(4,5),C;

C=A+B;
C.ShowComplex( );

return 0;
}
我觉得楼主的程序这么改一下会好一点


本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-01-13 08:28
快速回复:[原创]非托管类中的运算符重载
数据加载中...
 
   



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

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