Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!udel!rochester!kodak!ektools!randolph From: randolph@ektools.UUCP (Gary L. Randolph) Newsgroups: comp.lang.c++ Subject: Re: private to a class or to an object? Message-ID: <2125@ektools.UUCP> Date: 20 Sep 89 17:04:33 GMT References: <517@wizard.UUCP> Sender: randolph@ektools (Gary L. Randolph) Reply-To: randolph@ektools.UUCP (Gary L. Randolph) Organization: Eastman Kodak, Dept. 47, Rochester NY Lines: 46 In article <517@wizard.UUCP> john@wizard.UUCP (John Danner) writes: =Why is the following piece of code acceptable to cfront 1.2? =class flug ={ = private: = void printit() = { = printf("xy are %d %d\n",x,y); = } = int x,y; = public: = flug* z; = flug() = { = }; = void setxy(int a, int b) = { = x = a; = y = b; = } = void printz() = { = z->printit();//no syntax error = z->x = 6;//no syntax error = z->y = 7;//no syntax error = z->printit(); = } = =}; = main() ={ = flug a,b; = a.z = &b; = b.setxy(1,0); = a.printz(); =// printf("a.z->x = %s, a.z->y = %s\n",a.z->x,a.z->y);//syntax error private =} = =Shouldn't private data be private to a single object and not accessible =to any object of that class? Is this something that is safe to take =advantage of as far as compatibility with future versions of cfront? No, C++ is type based. This was brought up several months ago but is well worth mentioning periodically. The example in Stroustrup that points this out is on page 175. Tiny is a class that has operator=() overloaded so that it accesses the private variable, v, of another Tiny object.