TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BLAKE GAFFNEY
from: KURT KUZBA
date: 1998-03-17 08:02:00
subject: Scope of qualified declar

BG>   Is this valid C++ code? And would identifier "qwe" in the
BG>   bizarre definition of foo() refer to ::qwe or bar::qwe
BG>   (illegal anyway)?
BG> int qwe;
BG> int foo();
BG> class bar {
BG> public:
BG>  int qwe;
BG>  int ::foo() {return qwe;}
BG> };
   Try like this:
#include 
#include 
int qwe = 1;
int foo() { return qwe; }
class Scopetest {
public:
   Scopetest();
   int foo()       { return qwe; }
   int foofoo()    { return ::foo(); }
   int foofoofoo() { return ::qwe; }
private:
   int qwe;
};
Scopetest::Scopetest() { qwe = 2; }
int main(void)
{
   Scopetest test;
   cout << "\nGlobal : " << foo()
        << "\nClass  : " << test.foo()
        << "\nGClass : " << test.foofoo()
        << "\nCGlobl : " << test.foofoofoo()
        << endl;
   getch();
   return 0;
}
> ] By tomorrow, this will all seem like a dream................
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

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™.