public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Missing virtual functions
@ 1997-08-27  7:06 Eric Britten
  1997-09-01 18:30 ` Fergus Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Britten @ 1997-08-27  7:06 UTC (permalink / raw)
  To: gnu-win32

Yesterday I found that if one declares virtual functions in a class
like:

class A
{
    A();
    virtual void B();
};

and the definitions for the functions(inline or external) are not found
by the linker then two types of linking errors result.

1.  Undefined reference to a vtable in the constructors of the class.
2.  Undefined reference to any other inline functions of the class that
are used by other code.

It took me a while to figure out that if all virtual functions are
defined, then these errors go away.  Is this GNU specific?  It would
help if the linker complained of undefined references to the virtual
function without a definition, rather than the missing vtable.  Of
course this would help those unfamiliar with this error, I already know
the cause.

Eric Britten

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Missing virtual functions
  1997-08-27  7:06 Missing virtual functions Eric Britten
@ 1997-09-01 18:30 ` Fergus Henderson
  0 siblings, 0 replies; 2+ messages in thread
From: Fergus Henderson @ 1997-09-01 18:30 UTC (permalink / raw)
  To: ebritten; +Cc: gnu-win32

This is an off-topic answer to an off-topic question about GNU C++.

Eric Britten <ebritten@uci.edu> writes:

>Yesterday I found that if one declares virtual functions in a class
>like:
>
>class A
>{
>    A();
>    virtual void B();
>};
>
>and the definitions for the functions(inline or external) are not found
>by the linker then two types of linking errors result.
>
>1.  Undefined reference to a vtable in the constructors of the class.
>2.  Undefined reference to any other inline functions of the class that
>are used by other code.
>
>It took me a while to figure out that if all virtual functions are
>defined, then these errors go away.  Is this GNU specific?

The exact error messages you get are probably specific to GNU C++.
However, the fact that you do get errors if virtual functions
are not defined is not GNU specific.  The GNU behaviour conforms
to the draft ANSI/ISO C++ standard, which says that programs must
contain a definition of every virtual function.  (Implementations
are not _required_ to diagnose this error, however, so such code
_may_ work on other compilers...)

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: < http://www.cs.mu.oz.au/~fjh >   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-09-01 18:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-08-27  7:06 Missing virtual functions Eric Britten
1997-09-01 18:30 ` Fergus Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).