This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
undefined virtual table: a misleading error message in egcs-2.91.66
- To: gcc-bugs at gcc dot gnu dot org
- Subject: undefined virtual table: a misleading error message in egcs-2.91.66
- From: "Amit S. Kale" <akale at veritas dot com>
- Date: Mon, 15 May 2000 13:08:06 +0530
Hi,
I got a misleading error message about an undefined reference to a virtua=
l
table. gcc-bugs Jan. 2000 archives contain a posting 'EGCS 2.95.2 C++ bu=
g:
undefined reference for virtual table' reporting a similar problem with
no further replies.
A program given below shows the problem. If defines a class foo with a pu=
re
virtual function fun. Another class bar is derived from foo. It defines f=
un
foo and a constructor. If implementation for function fun in class foo is=
not
provided then the compiler gives a misleading error: undefined reference =
to
'bar virtual table'
Compiler sems to generate virtual table noly when a virtual function is
implemented. Shouldn't virtual table be generated whenever it is referenc=
ed,
e.g in constructor?
Can this be fixed?
Thanks.
--=20
Amit Kale
Veritas Software ( http://www.veritas.com )
class foo {
public:
=09virtual void fun ( ) =3D 0;
};
class bar :
=09public foo {
public:
=09bar ( ) ;
=09void fun ( );
};
bar::bar ( )
{
}
/*
* For getting around error : undefined reference to `bar virtual table'
* uncomment this function
*/
/*
void
bar::fun ( )
{
}
*/
int
main ( )
{
=09bar *b =3D new bar;
=09return 0;
}