home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Newsgroups: comp.lang.c++
- Subject: Re: classes referenced each in their declaration
- Message-ID: <1992Jul21.214406.7921@murdoch.acc.Virginia.EDU>
- Date: 21 Jul 92 21:44:06 GMT
- References: <1992Jul21.174445.24733@menudo.uh.edu>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Organization: University of Virginia
- Lines: 39
-
- qincao@cs.uh.edu (Qin Cao) writes:
- > I am implementing an interface with C++. I need to declare several classes
- > which are referenced each other in their definition. If I used pointer, then
- > it works fine, but I really want to use dot notation to refer the class
- > member, instead of "->" notation when using pointer. ...
- >
- > class X;
- > class Y;
- >
- > class X {
- > int a;
- > Y b; // if I put "Y *b;" here, it works fine
- > };
- >
- > class Y {
- > int c;
- > X d;
- > };
-
- Please use references. I just tested the following in
- the GNU C++ compiler.
-
- class X;
-
- class Y {
- X& x;
- public:
- Y();
- };
-
- class X {
- Y y;
- public:
- X() {}
- };
-
- Y::Y(): x(*new X) {}
-
- -Sekar
-