Mail Archives: djgpp/2000/12/26/17:49:01
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 -