Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!haven!umd5!crabcake!zhu From: zhu@crabcake.cs.jhu.edu (Benjamin Zhu) Newsgroups: comp.lang.c++ Subject: Re: Scoping bug??? Message-ID: <1251@crabcake> Date: 11 Apr 90 23:04:11 GMT References: <2582@ektools.UUCP> Reply-To: zhu@crabcake.cs.jhu.edu (Benjamin Zhu) Organization: Johns Hopkins University CS Dept. Lines: 56 In article <2582@ektools.UUCP> randolph@ektools.UUCP (Gary L. Randolph) writes: [stuffs deleted here] >There appears to be a scoping problem with locally defined classes >that contain a member function. The following example compiles without >a hitch on my Sun. I am using Sun's 2.0 cfront. > >By commenting out the member function (and the call) the compiler >correctly generates an error, but as is, the compiler does not >recognize a problem. Am I missing somthing? Sure smells like a bug. > > >#include >main() >{ >void func(); //prototype > >//local class definition >class X{ > public: > int i; > float f; > void printIt(){cout<<"\nHello\n";} >}c; >c.i = 1; >c.f = 3.3; >c.printIt(); >cout<<"\ni: "<func(); >} > >void func(){ >X x; //COMPILER TAKES THIS >x.i = 2; >x.f = 44.5; >cout<<"\ni: "<} > > >Thanks, > Gary Our AT&T cfront 2.0 also displays the same problem. Personally I believe it is a scoping bug. Actually there is a paragraph concerning this in Lippman's C++ Primer (pp222-223). A class can be defined within the scope of a file. Its class name is visible only within the boundary of its local scope. blah, blah, blah... I do not know why we have this bug here. Does AT&T give different versions of the cfront translator?! Benjamin Zhu ======================================================================= Sorry, but I have no disclaimer for you. =======================================================================