"[in-charge]"

D

Dario Kampkaspar

Hi, need your help again.
Compiling a code gives me the following:

home/phlox/sources/msw/server/einspieler.cc:430: undefined reference
to `ObjektFehler::~ObjektFehler [in-charge]()'
einspieler.o(.text+0x1f42):/home/phlox/sources/msw/server/einspieler
.cc:446: undefined reference to `ObjektFehler::~ObjektFehler
[in-charge]()
[...]

l.430 in einspieler.cc looks like this:

catch (ObjektFehler fehler) {};

An included file contains the definition:

class ObjektFehler : exception{
[...]
virtual ~ObjektFehler() throw();
}

Any ideas, what to do? Thx in advance!

Dario
 
J

Jonathan Turkanis

Dario Kampkaspar said:
Hi, need your help again.
Compiling a code gives me the following:

home/phlox/sources/msw/server/einspieler.cc:430: undefined reference
to `ObjektFehler::~ObjektFehler [in-charge]()'
einspieler.o(.text+0x1f42):/home/phlox/sources/msw/server/einspieler
.cc:446: undefined reference to `ObjektFehler::~ObjektFehler
[in-charge]()
[...]

l.430 in einspieler.cc looks like this:

catch (ObjektFehler fehler) {};

An included file contains the definition:

class ObjektFehler : exception{
[...]
virtual ~ObjektFehler() throw();

This is just a declaration. It must be defined somewhere. Is it?

Jonathan
 
D

Dario Kampkaspar

Jonathan Turkanis said:
Dario Kampkaspar said:
Hi, need your help again.
Compiling a code gives me the following:

home/phlox/sources/msw/server/einspieler.cc:430: undefined reference
to `ObjektFehler::~ObjektFehler [in-charge]()'
einspieler.o(.text+0x1f42):/home/phlox/sources/msw/server/einspieler
.cc:446: undefined reference to `ObjektFehler::~ObjektFehler
[in-charge]()
[...]

l.430 in einspieler.cc looks like this:

catch (ObjektFehler fehler) {};

An included file contains the definition:

class ObjektFehler : exception{
[...]
virtual ~ObjektFehler() throw();

This is just a declaration. It must be defined somewhere. Is it?

Nope, didn't find any defintion. But, isn't throw() a command making
~ObjektFehler both declared and defined?

As I do not know what my friend exactly wanted this to do and I didn't
do much with exception handling up to now, any idea what I could do to
make this run? How should a minimum definition of this look like?

Thanks,
Dario
 
J

Jonathan Turkanis

Dario Kampkaspar said:
Jonathan Turkanis said:
Dario Kampkaspar said:
Hi, need your help again.
Compiling a code gives me the following:

home/phlox/sources/msw/server/einspieler.cc:430: undefined reference
to `ObjektFehler::~ObjektFehler [in-charge]()'
einspieler.o(.text+0x1f42):/home/phlox/sources/msw/server/einspieler
.cc:446: undefined reference to `ObjektFehler::~ObjektFehler
[in-charge]()
[...]

l.430 in einspieler.cc looks like this:

catch (ObjektFehler fehler) {};

An included file contains the definition:

class ObjektFehler : exception{
[...]
virtual ~ObjektFehler() throw();

This is just a declaration. It must be defined somewhere. Is
it?

Nope, didn't find any defintion. But, isn't throw() a command making
~ObjektFehler both declared and defined?

As I do not know what my friend exactly wanted this to do and I didn't
do much with exception handling up to now, any idea what I could do to
make this run? How should a minimum definition of this look like?

throw() is an exception specification -- in this case a promise not to
throw any exceptions, which the compiler will enforce to a limited
extent. Destructors should almost never throw exceptions (I say almost
because basic_ostream::sentry::~sentry() can throw). Some people will
say that instead of an exception specification it would be better here
just to have a comment: // never throws.

At any rate, adding an exception specification does not count as a
definition (or as a 'command', for that matter). To provide a
definition, all you need is this:

virtual ~ObjektFehler() { }

(Of course, depending on the details of the implementation, the
destructor may need to do more.)

Jonathan
 
D

Dario Kampkaspar

Hi again,
home/phlox/sources/msw/server/einspieler.cc:430: undefined reference
to `ObjektFehler::~ObjektFehler [in-charge]()'
einspieler.o(.text+0x1f42):/home/phlox/sources/msw/server/einspieler
.cc:446: undefined reference to `ObjektFehler::~ObjektFehler
[in-charge]()
[...]

l.430 in einspieler.cc looks like this:

catch (ObjektFehler fehler) {};

An included file contains the definition:

class ObjektFehler : exception{
[...]
virtual ~ObjektFehler() throw();
throw() is an exception specification -- in this case a promise not to
throw any exceptions, which the compiler will enforce to a limited
extent. Destructors should almost never throw exceptions (I say almost
because basic_ostream::sentry::~sentry() can throw). Some people will
say that instead of an exception specification it would be better here
just to have a comment: // never throws.

At any rate, adding an exception specification does not count as a
definition (or as a 'command', for that matter). To provide a
definition, all you need is this:

virtual ~ObjektFehler() { }

Okay, now it looks like this.
objekt.h (18):
virtual ~ObjektFehler() throw();

objekt.cc (11):
virtual ObjektFehler::~ObjektFehler(){}

This gives me the following error:

objekt.cc:11: error: virtual outside class declaration
objekt.cc:11: error: declaration of `virtual ObjektFehler::~ObjektFehler()'
throws different exceptions
objekt.h:18: error: than previous declaration `virtual
ObjektFehler::~ObjektFehler() throw ()'

Or should I put it elsewhere?

Greets

Dario
 
J

Jonathan Turkanis

Dario Kampkaspar said:
Hi again,
Okay, now it looks like this.
objekt.h (18):
virtual ~ObjektFehler() throw();

objekt.cc (11):
virtual ObjektFehler::~ObjektFehler(){}

This gives me the following error:

objekt.cc:11: error: virtual outside class declaration
objekt.cc:11: error: declaration of `virtual ObjektFehler::~ObjektFehler()'
throws different exceptions
objekt.h:18: error: than previous declaration `virtual
ObjektFehler::~ObjektFehler() throw ()'

The error messages are pretty clear: First, leave 'virtual' off the
definition; keep it only on the declaration. (BTW, most of the time it
will be okay to include the empty definition within the class
definition.) Second, the exception specifications on both declaration
and definition must match.

jonathan
 
D

Dario Kampkaspar

Hi,
The error messages are pretty clear: First, leave 'virtual' off the
definition; keep it only on the declaration. (BTW, most of the time it
will be okay to include the empty definition within the class
definition.) Second, the exception specifications on both declaration
and definition must match.

Okay, objekt.h:
virtual ~ObjektFehler throw();

objekt.cc:
ObjektFehler::~ObjektFehler() throw() {};

produces
phlox@dario:~/sources/msw/objekte> gcc -c -o objekt.o objekt.cc
In file included from objekt.cc:1:
objekt.h:19: error: variable or field `ObjektFehler' declared void
objekt.h:19: error: `ObjektFehler' declared as a `virtual' field
objekt.h:19: error: parse error before `throw'
objekt.h:19: error: field `int ObjektFehler::ObjektFehler' with same name as
class
objekt.h:10: error: looser throw specifier for `virtual
ObjektFehler::~ObjektFehler()'
/usr/include/g++/exception:56: error: overriding `virtual
std::exception::~exception() throw ()'
objekt.h:10: error: looser throw specifier for `virtual
ObjektFehler::~ObjektFehler()'
/usr/include/g++/exception:56: error: overriding `virtual
std::exception::~exception() throw ()'
objekt.h:10: error: looser throw specifier for `virtual
ObjektFehler::~ObjektFehler()'
/usr/include/g++/exception:56: error: overriding `virtual
std::exception::~exception() throw ()'
objekt.cc:16: error: definition of implicitly-declared `virtual
ObjektFehler::~ObjektFehler()'
objekt.cc:16: error: declaration of `virtual ObjektFehler::~ObjektFehler()
throw ()' throws different exceptions
objekt.h:10: error: than previous declaration `virtual
ObjektFehler::~ObjektFehler()'

But as you said, objekt.h:
virtual ~ObjektFehler() throw(){};
works.

I also found, that some of these glitches were caused by the Makefile...
Well, I'm still puzzled a bit, but I'll investigate this.

Thanks for your help, Jonathan!

Dario
 
J

Jonathan Turkanis

Dario Kampkaspar said:
Hi,


Okay, objekt.h:
virtual ~ObjektFehler throw();

You still need the parentheses after ObjektFehler.

virtual ~ObjektFehler() throw();

The parentheses after ObjektFehler delimit the argument-list; those
after throw delimit the list of allowed exceptions.

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top