[comp.sys.mac.programmer] And now a question about OOPs and LSC

jtn@potomac.ads.com (John T. Nelson) (09/23/90)

And now a question about OOPs and Lightspeed C.  I have some code that
builds on a superclass and each of the subclasses uses only new
methods but no new instance variables.  It's pretty straightforward.
I have each subclass in a .h file and the methods in .c files for each
of the classes.  Then I compile and link and the linker tells me my
methods aren't defined!  Yet the methods are delcared in the class
definitions and the methods most certainly do exist in the files
compiled.  Yes, each of the methods is preceded by the subclass
name...

Link::getALink(void *, KEY_TYPE zot)
{
}

etc... and the subclasses look something like this...


struct classA : primeClass {
	void *constructor(void);
	void getALink(void *, KEY_TYPE);
};

yet MANY of the superclass methods come up undefined.  ANyone have a
clue as to what's going wrong?



-- 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ORGANIZATION:  Advanced Decision Systems   GEOGRAPHIC: Arlington, VA
UUCP:          kzin!speaker@mimsy.umd.edu  INTERNET:   jtn@potomac.ads.com
SPOKEN:        Yo... John!                 PHONE:      (703) 243-1611
PROJECT:       The Conrail Locomotive/Harpsichord Fusion Program
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

phils@chaos.cs.brandeis.edu (Phil Shapiro) (09/24/90)

If you have *any* method that's not defined for a class, you will get
link errors for the entire class (I believe).  Therefore, if you have
a method declared in some superclass that's not defined, none of its
subclasses will link properly.

	-phil shapiro, symantec tech support
--
Phil Shapiro
phils@chaos.cs.brandeis.edu

jtn@potomac.ads.com (John T. Nelson) (09/25/90)

In article <PHILS.90Sep24100031@chaos.cs.brandeis.edu> phils@chaos.cs.brandeis.edu (Phil Shapiro) writes:
>If you have *any* method that's not defined for a class, you will get
>link errors for the entire class (I believe).  Therefore, if you have
>a method declared in some superclass that's not defined, none of its
>subclasses will link properly.


This seems to be the case, and the *only* method  for which there
wasn't a definition was "constructor."  I defined "constructor" as
follows in the subclasses and everything linked fine.  What bugs me is
that "constructor" is supposed to be defined and inherited from the
superclass whenn the subclass is defined.

struct A_Class : Superclass {
	void *constructor(void);

	void moreMethods(void);
	};

A_Class should get Superclass's constructor yet in my project it
doesn't so I define the following for A_Class:

void A_Class::constructor()
{

this = inherited::constructor();
return this;
}

and the linker is happy.  This SHOULDN'T be necessary though!


-- 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ORGANIZATION:  Advanced Decision Systems   GEOGRAPHIC: Arlington, VA
UUCP:          kzin!speaker@mimsy.umd.edu  INTERNET:   jtn@potomac.ads.com
SPOKEN:        Yo... John!                 PHONE:      (703) 243-1611
PROJECT:       The Conrail Locomotive/Harpsichord Fusion Program
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

phils@chaos.cs.brandeis.edu (Phil Shapiro) (09/25/90)

In article <9189@potomac.ads.com> jtn@potomac.ads.com (John T. Nelson) writes:
>   [ stuff deleted ]
>
>   struct A_Class : Superclass {
>	   void *constructor(void);
>
>	   void moreMethods(void);
>	   };
>
>   A_Class should get Superclass's constructor yet in my project it
>   doesn't so I define the following for A_Class:
>
>   void A_Class::constructor()
>   {
>
>   this = inherited::constructor();
>   return this;
>   }
>
>   and the linker is happy.  This SHOULDN'T be necessary though!

When you mention a method name in an object's defintion, you are
telling the compiler that you intend to define that method for that
particular class.  By declaring constructor, you indicate that you
wish to override Superclass's constructor method (or declare a new
method named constructor).  If you want to inherit a method from a
superclass, don't mention it in your object's defintion.

	-phil shapiro, symantec tech support
--
Phil Shapiro
phils@chaos.cs.brandeis.edu