| delorie.com/archives/browse.cgi | search |
| From: | Jean-Gaël GRICOURT <jean-gael DOT gricourt AT snet DOT net> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Pb with private members ... |
| Date: | Sat, 01 Feb 1997 14:53:59 -0400 |
| Organization: | "SNET dial access service" |
| Lines: | 42 |
| Message-ID: | <32F39147.6896@snet.net> |
| NNTP-Posting-Host: | brpt01-sh1-port25.snet.net |
| Mime-Version: | 1.0 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Please tell me what do you think about this code ?
------------------------------
#include <iostream.h>
class Object
{
private:
int data;
public:
Object(int=0);
Object(Object&);
ShowData();
};
Object::Object(int d)
{ data=d; }
Object::Object(Object &o)
{ data=o.data; }
Object::ShowData()
{ return data; }
main()
{
Object InstObject1(5),InstObject2;
InstObject2=InstObject1;
cout<<InstObject2.ShowData();
return 0;
}
-----------------------------------
In the constructor "Object(Object &o)", the member "o.data" is accessed
although it is a private member !
Is there something wrong ?
I used DJGPP 2.01 and I had no pb to compile this and it worked fine.
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |