home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!bnr.co.uk!uknet!axion!gssec.bt.co.uk!mjackson
- From: mjackson@gssec.bt.co.uk (Mark Jackson)
- Newsgroups: comp.lang.c++
- Subject: Re: prototyping object?
- Message-ID: <1992Dec23.170803.19309@gssec.bt.co.uk>
- Date: 23 Dec 92 17:08:03 GMT
- Sender: usenet@gssec.bt.co.uk
- Followup-To: <1992Dec22.114524.421@ghost.dsi.unimi.it>
- Organization: BT, Software Engineering Centre, Glasgow, Scotland
- Lines: 119
-
-
- In article <1992Dec22.114524.421@ghost.dsi.unimi.it>,
- valentm@ghost.dsi.unimi.it (marco valentini) writes:
- |>
- |> I have written the following code:
- |> class paolo; //!Is Right this ??????
- |> object pippo
- |> {
- |> paolo* p;
- |> public:
- |> void ....
- |> ..... (various methods)
- |>
- |> }
- |> object paolo
- |> {
- |> pippo* pi;
- |> public:
- |> int ...
- |> ...(variuos methods)
- |> }
- |>
-
- Firstly, it is not recommended to have two classes mutually dependent on
- each other.
- i.e. pippo needs to know about paulo, and vice-versa. Check your design.
-
- Secondly, there is nothing wrong with your 'forward declaration' of
- class paulo.
- What the compilation error sounds like is a module problem.
- Separate the implementation from the class interface. i.e.
-
- in file 'pippo.h'------------------------
-
- class paulo; // Forward declaration. O.K.
-
- class pippo
- {
- paulo* p;
-
- public:
- (interfaces to various methods)
- void setPaulo(paulo* newP);
- int usePaulo();
- int doSomething();
- };
-
- (end of 'pippo.h')------------------------
-
- in file 'paulo.h'--------------------------
-
- class pippo; // Forward declaration. O.K.
-
- class paulo
- {
- pippo* pi;
-
- public:
- (interfaces to various methods)
- int setPippo(pippo* newPi);
- int usePippo();
- int doSomethingElse();
- };
-
- (end of 'paulo.h')-------------------------
-
- Then in file 'pippo.cc' (or whatever file extension you use)
-
- #include "pippo.h"
- #include "paulo.h" // This gives you access to paulo's methods
-
- void pippo::setPaulo(paulo* newP)
- {
- p = newP;
- }
-
- int pippo::usePaulo()
- {
- if( p != NULL )
- return( p->doSomethingElse() );
- else
- return( -1 );
- }
-
- (end of 'pippo.cc')-------------------------
-
- Same thing for paulo.cc
-
- #include "paulo.h"
- #include "pippo.h" // This gives you access to pippo's methods
-
- void paulo::setPippo(pippo* newP)
- {
- pi = newP;
- }
-
- int paulo::usePippo()
- {
- if( pi != NULL )
- return( pi->doSomething() );
- else
- return( -1 );
- }
-
- (end of 'paulo.cc')-------------------------
-
- Hope this helps, Merry Christmas &c.
-
- Mark Jackson
-
- --
-
- !!!!!!! ___________________________________
- +(.)(.) ( )
- C > ) | HO, HO. MERRY CHRISTMAS, NETTERS |
- \ V / ----(___________________________________)
- ---
-
- P.S. I tried email, but got 'Service Unavailable'....
-