Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcsun!ukc!dcl-cs!aber-cs!emerald!pcg From: pcg@emerald.cs.aber.ac.uk (Piercarlo Grandi) Newsgroups: comp.lang.c++ Subject: Re: Define's and Devices. Message-ID: Date: 27 Nov 89 22:51:40 GMT References: <478@hades.OZ> Sender: pcg@aber-cs.UUCP Organization: Coleg Prifysgol Cymru Lines: 78 In-reply-to: ing@hades.OZ's message of 25 Nov 89 00:39:45 GMT In article <478@hades.OZ> ing@hades.OZ (Ian Gold) writes: The first problem is the "#define syndrome". Assume I have a keyboard defined as enum keys { ENTER = 0x13, ESC = 0x27, A_CHR = 0x41, B_CHR = 0x42, . . . }; In C I would declare this globally so everybody knows about it. What I would like to do in C++ is something like class keys { public: enum keys { ENTER = 0x13 . . . }; }; class program : keys { public: void program :: function(void) { return keys::ENTER; } } and allow it to be inherited only by the classes that need it. The problem is that the above example is NOT C++. Actually it is C++ 2.0; in C++ 1.2 etc... you can instead use static consts, in some compilers at least [in 1.2 you cannot initialize a class static, but a const often can...]. I realise that this is much slower than using #defines and would only be useful if one uses multiple inheritance. Without discussing this, neither assertion is necessarily true. Use enums, not #defines, in C++ 2.0. My second problem is that of devices. Say I have three CPU's 2 keyboards and half a VDU. Somewhere I must declare these as being the only devices avaliable. IS THE FOLLOWING CODE THE "CORRECT" WAY TO HANDLE THE SITUATION. class program { CPU cpu1; CPU cpu2; CPU cpu3; KEYBOARD keyboard1; KEYBOARD keyboard2; VCU vdu(0.5); boolean program(); public: go() { keyboard1.reset(); keyboard2.reset(); vdu.reset(); program(); } }; This is debatable. Function/control decomposition need not be mapped onto data abstraction. This may well be excessive application of Object Orientedness. -- Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcvax!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk