ksand@apple.com (Kent Sandvik) (02/01/91)
I'm not sure that this is syntactically OK, but I would like to
achieve better function return value scoping using enums. Ex:
class TFoo {
public:
TFoo(){};
virtual eFoobar GetStatus(void){ return fStatus;};
enum eFoobar {OK, NOK, MAYBE};
private:
eFoobar fStatus;
// ....
};
I'm using Mac MPW 1.0 C++ (AT&T 2.0 derivate). I also tried with
typecasting, but the compiler did not like this either. Anyway
it complains about eFoobar not being a type name.
Are there any tricks to achieve this, am I lost in the Syntax Sugarland
of C++, or would this be another cute feature that could kill Ada?
Regards,
Kent Sandvik
rae@gpu.utcs.toronto.edu (Reid Ellis) (02/03/91)
Kent Sandvik <ksand@apple.com> writes: >I'm not sure that this is syntactically OK, but I would like to >achieve better function return value scoping using enums. Ex: > >class TFoo { >public: > TFoo(){}; > virtual eFoobar GetStatus(void){ return fStatus;}; > enum eFoobar {OK, NOK, MAYBE}; >private: > eFoobar fStatus; >}; The problem is that you are using the type 'eFoobar' before it is defined. Simply move the "enum eFoobar {..};" line to the top of the class and everything should be okay. Reid -- Reid Ellis 176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu CDA0610@applelink.apple.com || +1 416 446 1644
rmartin@clear.com (Bob Martin) (02/04/91)
In article <48742@apple.Apple.COM> ksand@apple.com (Kent Sandvik) writes: >I'm not sure that this is syntactically OK, but I would like to >achieve better function return value scoping using enums. Ex: > >class TFoo { >public: > TFoo(){}; > virtual eFoobar GetStatus(void){ return fStatus;}; > enum eFoobar {OK, NOK, MAYBE}; >private: > eFoobar fStatus; >// .... >}; > >I'm using Mac MPW 1.0 C++ (AT&T 2.0 derivate). I also tried with >typecasting, but the compiler did not like this either. Anyway >it complains about eFoobar not being a type name. >Kent Sandvik Kent: I got the same error using SUN's 2.0 compiler. But when I moved the enum statement up above the TFOO(){} constructor the error went away. -- +-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for | | rmartin@clear.com |:R::R:C::::M:M:M:M:| my words but me. I want | | uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all | +----------------------+:R::R::CCC:M:::::M:| the blame. So there. |