This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

undefined virtual table: a misleading error message in egcs-2.91.66


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]