Path: utzoo!attcan!uunet!samsung!munnari.oz.au!basser!ultima!hades!ing From: ing@hades.OZ (Ian Gold) Newsgroups: comp.lang.c++ Subject: Define's and Devices. Keywords: defines, devices Message-ID: <478@hades.OZ> Date: 25 Nov 89 00:39:45 GMT Organization: Ausonics Pty Ltd, Sydney, Australia Lines: 85 I would like to write object orientated code in C++ but am having trouble coping with two concepts. Perhaps my C background is plaguing me. Perhaps I am a hypocondriac. 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. I realise that this is much slower than using #defines and would only be useful if one uses multiple inheritance. The problem is that the above example is NOT C++. DOES ANYBODY KNOW HOW OR IF I CAN ACHIEVE THE ABOVE IDEAS EFFICIENTY IN C++ ! Is the following code the best way out. class keys { public: int ENTER() { return 0x13; } . . . }; class program : keys { public: void program :: function(void) { return keys::ENTER(); } } 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(); } }; void main(void) { program a; a.go(); }