home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!uwm.edu!ogicse!emory!nntp.msstate.edu!cee1
- From: cee1@ra.msstate.edu (Charles Evans)
- Newsgroups: comp.lang.c++
- Subject: Problems with int as enum
- Message-ID: <1992Sep13.222623.21562@ra.msstate.edu>
- Date: 13 Sep 92 22:26:23 GMT
- Article-I.D.: ra.1992Sep13.222623.21562
- Organization: Mississippi State University
- Lines: 70
-
- BC++ 2.0 :
-
- (Trying to learn some C++ here in my spare time.. well the first real program
- in book I am using, "C++ for C Programmers", has this [edited for brevity])
-
- #include <stream.h>
- #include <stdlib.h> // optional
-
- int random(void);
-
- enum suit { clubs, diamonds, hearts, spades };
-
- struct card { suit s; int pips };
-
- ...
-
- void init_deck(card d[])
- {
- for (int i = 0; i < 52; ++i)
- {
- d[i].s = (i / 13); // enum as int ? -- WARNING #1
- d[i].pips = 1 + i % 13;
- }
- }
- void shuffle(card d[])
- {
- for (int i = 0; i < 52; ++i)
- {
- int k = random() % 52 // choose a random card
- card t = d[i]; // swap two cards ERROR #2, #3
- d[i] = d[k];
- d[k] = t; // ERROR #4
- }
- }
-
- ....
-
- int main(void)
- {
- card deck[52];
-
- init_deck(deck);
- pr_deck(deck);
- shuffle(deck);
- pr_deck(deck);
- return(0);
- }
-
- -----
-
- WARNING #1 : Assigning int to suit in function init_deck(card far*)
- ERROR #2 : Undefined symbol 'card' in function shuffle(card far*)
- ERROR #3 : Undefined symbol 't' in function shuffle(card far*)
- ERROR #4 : Undefined symbol 't' in function shuffle(card far*)
-
- ---
-
- So whats the problem with swapping 'cards'? cant you define a 'card t'??
- Help. No clue.
- No sleep.
-
- chuck
-
-
-
- --
- +--------------------+-----------------------+------------------------+
- | Charles E. Evans | cee1@ra.msstate.edu | All things are green |
- | iDLE CHATTEr | cee1@MSSTATE.BITNET | unless they are not. |
- +--------------------+-----------------------+------------------------+
-