Last active
May 8, 2016 21:44
-
-
Save naddison36/cf811f1da0562beb350f70f187982e72 to your computer and use it in GitHub Desktop.
== operator for enum's in Solidity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contract Card | |
| { | |
| enum Suit {Heart, Diamond, Shape, Club, Jocker} | |
| Suit public suit; | |
| enum Rank {Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace, Jocker} | |
| Rank public rank; | |
| function equal(Card card) returns (bool) | |
| { | |
| return suit == card.suit && rank == card.rank; | |
| } | |
| } |
Author
Author
parenthesis are needed when referencing an enum variable as it is a function. The following code compiles
contract Card
{
enum Suit {Heart, Diamond, Shape, Club, Jocker}
Suit public suit;
enum Rank {Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace, Jocker}
Rank public rank;
function equal(Card card) returns (bool)
{
return suit == card.suit() && rank == card.rank();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above is failing with the following error