🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #116

Mutually recursive class references

#116
From: Nate Osgood
Date: Mon, 27 Jul 1992 19:40
62 lines
2631 bytes
I'm hoping to switch from g++ version 1.40 to gcc 2.2.2 as my primary
development platform.  Unfortunately, it seems that gcc 2.2.2 has a difficulty
with some of the code I've been compiling with 1.40.  I'm hoping that perhaps
someone on this newsgroup might be able to suggest a  simple solution to the
incompatibility.

The problem occurs when a method of a given class has a prototype that refers
to a class that has not yet been declared, but the method is used AFTER that
other class is declared.  As the GNU info documentation for gcc 2.2.2 notes,
for an arbitrary function the function prototype can be moved so that it also
occurs AFTER the structure (or class) definition, rather than before it.  But
if the function is a METHOD, one wants to put the declaration immediately
inside the class definition.  In this case, the code indicates mthe problem
more clearly than prose:

class first
{
 public:
  foo(class second);  /*  Reference to class that does not yet exist.
			Note that the declaration of class first cannot
			FOLLOW that of class second, since class second
			contains an OBJECT of type first
			*/
};

class second
{
  first f;		/*  Here is the reference to class first -- the need 
			for this reference forces class second to textually 
			follow class first in the program */

 public:
  
  bar(class second s) { return(f.foo(s)); }
			/*  Since class second has now been defined, gcc 2.2.2
			thinks that we are calling method foo of class first
			with a different type than it is expecting as a method
			argument.  It gives the complaint:


			 bad argument 0 for function `first::foo 
			(class first::second)' (type was class second)

			*/
};



	Would anyone happen to know if there an obvious workaround to this
problem that would not require removing the method from the class first
definition or converting the parameter to a "class second *"?
	
	Any help greatly appreciated!

	Nate Osgood

-- 
-------------------------------------------------------------------------------
Nate Osgood			| ARPA: hacrat@catfish.lcs.mit.edu
CS Graduate Student		| 
MIT LCS Room NE43-636		| UUCP: ...!uunet!catfish.lcs.mit.edu!hacrat
Technical Details
Message-ID: <1992Jul27.194051.21598@mintaka.lcs.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!wupost!gumby!yale!mintaka.lcs.mit.edu!CATFISH.LCS.MIT.EDU!hacrat

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!wupost!gumby!yale!mintaka.lcs.mit.edu!CATFISH.LCS.MIT.EDU!hacrat
From: hacrat@CATFISH.LCS.MIT.EDU (Nate Osgood)
Subject: Mutually recursive class references
Message-ID: <1992Jul27.194051.21598@mintaka.lcs.mit.edu>
Sender: news@mintaka.lcs.mit.edu
Organization: MIT Laboratory for Computer Science
Date: Mon, 27 Jul 1992 19:40:51 GMT
Lines: 62