Topic: Problems inlining virtual fns.
Author: jonathan@cae.ca (Jonathan Hutchinson)
Date: 1995/06/05 Raw View
I have a funny problem trying to inline a virtual function. I prefer
to keep the inlined definition in the .cxx file and no in the header
file for reasons of taste only.
Here is the printout of the code:
// DbObject.h
class DbObject {
public:
.
.
virtual MSG_ID_T put();
.
.
}
.
.
.
// DbObject.cxx
inline MSG_ID_T DbObject::put()
{
return executeRequest(GE_K_PUT_OPERATION_NAME);
}
and here is the error that my compiler gives.
Unresolved:
put__8DbObjectXv
I tried various changes, like defining the method as 'virtual inline'
in the class definition, but this did not change the outcome. If I
either remove the inline specifier, or place the function body in the
class declaration itself, then the problem disappears (the first
solution being unacceptable, and the second undesirable).
Is it not possible to inline virtual functions? The FAQ states that
virtual functions can only be inlined
"when the 'exact class' of the object which
is the target of the virtual call."
which implies that the compiler may not be able to honor the request
to inline the virtual function, but does not state that the compiler will
not create the virtual function.
I am stumped. Any help would be appreciated
Jonathan Hutchinson
jonathan@cae.ca