TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JERRY COFFIN
from: JONATHAN DE BOYNE POLLARD
date: 1997-10-21 01:18:00
subject: Why this construction?

 NH>> class button { 
 NH>> public:
 NH>>     enum status { out, in } ;
 NH>>     void set(status s) {state = s;}
 NH>>     status get() const {return state;}
 NH>> private:
 NH>>     status state ;
 NH>> };
 NH>>
 NH>> int 
 NH>> main()
 NH>> {
 NH>>     const button::status out = button::out;  // #1
 NH>>     const button::status in  = button::in;   // #2
 NH>>     button panic;
 NH>>     panic.set(out);
 NH>> }
 NH>> Had the line
 NH>>         button panic;
 NH>> been declared first in main(), could the verbiage in the line marked
 NH>> #1 above have been written:
 NH>>         const panic.status out = button::out;   ????
 JC> No.  panic.status is private, [...] 
 JC> In addition, panic.status is a variable, not a type. [...]
I leave you alone for a few months, and look what happens.   (-:  
button::status is clearly *public* in the above code, and is clearly a type 
not a variable.
The correct answer to his question is, in fact, "no", but merely because one 
cannot use an enumeration tag with the '.' operator.  One can use enumeration 
tags with the "::" operator, and one can use the enumerators themselves with 
the '.' operator.  So the following is a legal alternative to the above line 
#1 (assuming the declaration of `panic' suggested):
        const button::status out = panic.out ;
Similarly, one can write things like
        panic.set(panic.out) ;
and
        if ( panic.get() == panic.in ) { /* ... */ }
This syntax, apparently, gets Turbo Pascal users very excited.  (-:
 ¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.