RE: [Dev-C++] Newbie linking errors: 'undefined reference'
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-02-09 22:10:00
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Devin Carless
> Sent: Saturday, February 09, 2002 11:55 PM
> To: Ioannis Vranos
> Cc: dev...@li...
> Subject: Re: [Dev-C++] Newbie linking errors: 'undefined reference'
>
> That's roughly what I thought. The function is, indeed,
> mine; I'm not using a graphics library. (The game is that
> simple.) I do have a definition in BaseBook.cpp. The
> definition refers to an object contained in the private
> section of BaseBook, MoveParch, which has its own Lookup
> function (I do it this way because subclasses of BaseBook may
> want to redefine BaseBook::Lookup... WomanQSPrototype.cpp is
> one of these subclasses.)
> So plainly the linker isn't /reaching/ the definition. The
> method I use does require a few daisy-chained functions
> (BaseBook::Lookup calling MoveParch::Lookup, and there are
> other, three-step ones.) I don't know if this could make a
> difference. It does not seem to depend upon the legality of the code.
>
> Ah. Genius lightbulb. Here's an example of something
> similar from a few days back:
>
> bool ManeuverList::SetManeuver( short int ManI, char* NameA, short int
> BaseModA)
> // Inlining this gives linker error 'Undefined reference
> // to ManeuverList::Setmaneuver'. Gotcha!
> // Same with the Index typedefl.
> {
> // Maneuver::Set checks to see if we can
> // set this maneuver.
> bool b;
> b = ManVec[ManI].Set( NameA, BaseModA );
> return b;
> }
>
> Index was typedefed as 'unsigned short int.' It worked
> perfectly well elsewhere. That, and making this function
> inline caused the undefined reference linker errors.
It may be for 1000 reasons, e.g. wrong or absense of definition of
ManVec, wrong operator[] definition for ManVec e.t.c..
> Previously, I was having trouble with size(): a while loop
> explicitly told me both A and B were false (where B included
> a size() function,) and A && B was false, /but while(A && B)
> would still run through./
> I don't know if that's related. But it does show the level
> of black-voodoo nbugs I'm running into. Two functions
> stopped giving errors when the definitions were moved from
> the .cpp to the .h.
Had you included the .cpp file in the project? Also if you have the
definition of a class in a .cpp file you must include a declaration of
the class in the scope you use it. For example:
in the a.cpp file:
class A
{
// definition
};
in the file you use it:
class A;
A a;
//..
An undefined reference to the
> deconstructor went away when I moved the deconstructor up a
> few lines! So whatever is wrong, it's subtle - too subtle for me.
Yes i am sure it is noy error from the compiler... May i suggest a great
C++ book? "The C++ Programming Language" 3rd Edition or Special Edition
by Bjarne Stroustrup, the creator of C++. And he doesn't teaches only
C++ but very useful techniques and software engineering. Definitely a
great book!
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|