delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/26/17:49:01

From: "Marp" <marp AT 0 DOT 0 DOT 0 DOT 0>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Throwing a class yeilds a linker error.
Date: Tue, 26 Dec 2000 17:04:22 -0500
Organization: MindSpring Enterprises
Lines: 58
Message-ID: <92b4kf$32$1@slb1.atl.mindspring.net>
References: <3a4a05d9 DOT 101250781 AT news DOT clmba1 DOT mo DOT home DOT com> <92b1jr$c2u$1 AT slb7 DOT atl DOT mindspring DOT net>
NNTP-Posting-Host: 04.30.99.66
X-Server-Date: 26 Dec 2000 22:03:59 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Err sorry. The mistake I pointed out was correct, but my explanation of why
it was wrong was itself wrong :-)

By using parentheses when you declare object b of type B, the compiler
thinks you're providing a local prototype of a function called b that
returns a type B object, and when you throw b, it thinks you're throwing a
function pointer, but there is no concrete definition for the function (and
therefore no way to determine its pointer), and you get a "undefined
reference" error as a result.

Marp

"Marp" <marp AT 0 DOT 0 DOT 0 DOT 0> wrote in message
news:92b1jr$c2u$1 AT slb7 DOT atl DOT mindspring DOT net...
> "Beldraen" <beldraen AT nowhere DOT com> wrote in message
> news:3a4a05d9 DOT 101250781 AT news DOT clmba1 DOT mo DOT home DOT com...
> > I'm trying to learn how to throw classes, but something weird is going
> > on.  Here's the code, which is right out of a book I am reading:
> >
>
> <snip>
>
> > void main(void)
> > {
> >    B b();
>
> You should not use parentheses when you don't pass any arguements to the
> constructor when instantiating an object. If you do, it requires you to
> define a constructor, which is why you get the "undefined reference" from
> the linker. If you remove the parentheses, the linker error goes away and
> your program does what you expect it to do (I verified this).
>
> Hope this helps.
>
> Marp
>
> >    try
> >    {
> >       throw b;
> >    }
> >    catch(B c)
> >    {
> >       cout << "Caught!" << endl;
> >    }
> > }
> >
> > Compiling works just fine.  But, ld returns an error:
> > undefined reference to 'b(void)'
> >
> > I've not been able to figure out if DJGPP can't throw classes or what.
> >
> > Thanks for you help,
> > Chad
> >
>
>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019