Using VC8, I create two modules similar to the following:
Header
class IFoo
{
virtual void Bar() = 0;
};
Module A
extern IFoo& Foo;
void DoStuff()
{
Foo.Bar();
}
Module B
IFoo& Foo = ConcreteFoo();
VC8 handles this by essentially treating 'Foo' as a pointer to an IFoo. Wherever it sees Foo.Bar() (even in module B), it derefences the pointer to get the object's vtable, looks up the address of Bar() and calls it. This is a little irritating since Foo does in fact refer to a concrete object and always will. It would be nice if you could do something like the following:
Module A
extern __concrete IFoo& Foo;
This would tell the compiler that you promise to provide a concrete object to back this reference. It could then generate a special external reference to Foo.Bar() and directly call the method without the double dereferencing.
As far as I can tell, there's no way to do this with Visual C++, which leads to two questions:
- Is there a way to get the VC compiler to generate the direct method call?
- Are there any other C++ compilers that can do it?