Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!ahodgson From: ahodgson@athena.mit.edu (Antony Hodgson) Newsgroups: comp.lang.c++ Subject: Re: Is it just me? Problem, need help... Message-ID: <1991Mar1.183433.10843@athena.mit.edu> Date: 1 Mar 91 18:34:33 GMT References: <13358@hubcap.clemson.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 41 In article <13358@hubcap.clemson.edu> grimlok@hubcap.clemson.edu (Mike Percy) writes: >This is a simplification of a real-code problem. >Any help would be appreciated! > >Turbo C++ Version 1.01 Copyright (c) 1990 Borland International >temp.cpp: >Error temp.cpp 10: 'func' is not a member of 'bar' in >function foo::barfunc() >*** 1 errors in Compile *** >-------------------------------------------------------------------- >class bar; > >class foo { > bar *barptr; >public: > void barfunc() { barptr->func(); } > void func(); >}; > > >class bar { > foo *fooptr; >public: > void foofunc() { fooptr->func(); } > void func(); >}; The problem is that at the time the compiler reaches the definition of foo::barfunc(), it doesn't know what members bar has. One solution is to not define the code for foo::barfunc() here, but wait until after class bar has been defined. If you want barfunc to be inline, use the inline qualifier when you define it later. An alternative is to change your design a bit. If both foo and bar have func() member functions which mean similar things, perhaps both of them should be derived from a common base class which has a virtual func(); both foo and bar will then inherit this routine and foo::barfunc() will know about it. Tony Hodgson ahodgson@hstbme.mit.edu