confusion with overloads of virtual/nonvirtual or bug in Intel compiler
Hi,
I have a base class:
class Allocator {
public:
// non virtual inline alloc used 99.9% of time
void* Alloc (size_t minSize)
{
return Alloc2(minSize, true);
}
virtual void* Alloc2 (size_t minSize, bool tally) = 0;
virtual void Free (void* p) = 0;
};
Obviously my various allocator classes extend Allocator and provide
implementations
for Alloc2 and Free. They are called BuddyHeap and SimpleAllocator and
VMHeap.
90% of time my apis use Allocator& but some apis just use VMHeap& since
the VM functions
have access to all of the members of VMHeap. This works fine.
However, if in Allocator, BuddyHeap, etc. I try to change the name of
Alloc2 to Alloc, using
name overloading between a non-virtual function and virtual function,
then in those
calls to Alloc with just 1 parameter, my Linux Intel C++ Compiler
cannot resolve Alloc
with one parameter when called from VMHeap& reference. It says I'm
missing the extra
parameter since VMHeap extends BuddyHeap and BuddyHeap only provides
the 2 param
version, hoping that the one param version (non-virtual inline) from
the base class would be used.
It seems that when there is overloading, the 2 param version of Alloc
hides the one param
version in the base class. The 2 workarounds are to use Alloc2 as
above and avoid
overloading, in which case the inline version of the base class is
found for VMHeap&, OR
with overloading, explictly declare the inline version in both
Allocator and BuddyHeap.
Is this an example of my lack of understanding C++ rules regarding
overloading of names
across virtual and non-virtual functions, or is it a bug in the Intel
C++ compiler?
Thanks,
Andy
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]