home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- From: nikki@trmphrst.demon.co.uk (Nikki Locke)
- Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
- ReplyTo: nikki@trmphrst.demon.co.uk
- Subject: Re: Problems with int as enum
- References: <1992Sep13.222623.21562@ra.msstate.edu>
- Distribution: world
- X-Mailer: cppnews $Revision: 1.16 $
- Organization: Trumphurst Ltd.
- Lines: 58
- Date: Tue, 15 Sep 1992 11:40:18 +0000
- Message-ID: <716582418snx@trmphrst.demon.co.uk>
- Sender: usenet@gate.demon.co.uk
-
-
- In article <1992Sep13.222623.21562@ra.msstate.edu> cee1@ra.msstate.edu (Charles Evans) writes:
-
- > 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
- You are assigning an integer to an enum. You need a cast here ...
- d[i].s = (suit)(i / 13);
-
- > 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
- You have a missing semicolon here, which causes the other errors ...
- 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
- > }
- > }
- > ...
- > -----
- >
- > 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*)
- >
- > ---
- ---
- Nikki Locke | | nikki@trmphrst.demon.co.uk
- Trumphurst Ltd. | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
- PC and Unix consultancy | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
- trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
- Demon.co.uk is a dial-up subscription access point to the Internet.
-