| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 581 人关注过本帖
标题:[求助]运算符重载问题!
取消只看楼主 加入收藏
loveaoao
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-8-3
收藏
 问题点数:0 回复次数:0 
[求助]运算符重载问题!

Card.cs

using System;
using System.Collections;
using System.Text;

namespace CardExample
{
public enum Suit
{
红心,
方块,
梅花,
黑桃
}
public enum Rank
{
Ace=1,
_2,
_3,
_4,
_5,
_6,
_7,
_8,
_9,
_10,
J,
Q,
K
}

public class Card
{
public static bool useTrumps;
public static Suit Trumps = Suit.梅花;
public static bool isAceHingh = true;
public readonly Suit suit;
public readonly Rank rank;
public override string ToString()
{
return ""+suit+rank;
}
private Card()
{

}
public Card(Suit newSuit, Rank newRank)
{
suit = newSuit;
rank = newRank;
}
public static bool operator ==(Card card1, Card card2)
{
return (card1.suit == card1.suit) && (card1.rank == card2.rank);
}
public static bool operator !=(Cards card1, Card card2)
{
return !(card1 == card2);
}
public override bool Equals(object card)
{
return this==(Card)card;
}
public override int GetHashCode()
{
return 13*(int)rank+(int)suit;
}
public static bool operator >(Card card1, Card card2)
{
if (card1.suit == card2.suit)
{
if (isAceHingh)
{
return (card1.rank > card2.rank) ^ (card2.rank = Rank.Ace);
}
else
{
return (card1.rank >= card2.rank);
}
}
else
{
if (useTrumps && (card2.suit = Card.Trumps))
{
return false;
}
else
{
return true;
}
}
}
public static bool operator <=(Card card1, Card card2)
{
return !(card1 > card2);
}
}
}

显示错误:
错误 1 运算符“CardExample.Card.operator ==(CardExample.Card, CardExample.Card)”要求也要定义匹配的运算符“!=”
错误 2 运算符“CardExample.Card.operator !=(CardExample.Cards, CardExample.Card)”要求也要定义匹配的运算符“==”
错误 3 运算符“CardExample.Card.operator >(CardExample.Card, CardExample.Card)”要求也要定义匹配的运算符“<”
错误 4 运算符“CardExample.Card.operator <=(CardExample.Card, CardExample.Card)”要求也要定义匹配的运算符“>=”
何解?
我是初学的啊!求各位大虾帮帮小弟!
搜索更多相关主题的帖子: 重载 运算符 
2006-08-05 12:48
快速回复:[求助]运算符重载问题!
数据加载中...
 
   



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

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