views:

40

answers:

1

I have written a class for managing GPU memory buffers.

I've got one method for building a buffer initialized with a chunk of CPU memory (if pData is null, then allocated block of GPU memory is not initialized, remaining with indeterminate values) and an overload for building it initialized with the same byte value:

IBuffer* CreateBuffer(IDevice* pDevice, int byteWidth, const void* pData);
IBuffer* CreateBuffer(IDevice* pDevice, int byteWidth, byte fillValue);

Use cases are:

CreateBuffer(pDev, 512, pData); //OK
CreateBuffer(pDev, 512, nullptr); //OK
CreateBuffer(pDev, 512, 0xCD); //OK
CreateBuffer(pDev, 512, 0x01); //OK
CreateBuffer(pDev, 512, 0x00); //error: ambiguous call to overloaded function

Sure, I can force a cast or change the method name for solving the issue. I'm just wondering if there's a more serious issue somewhere causing that or if it's just a compiler restriction/bug.

Thanks!

+3  A: 

This is "By Design". In this case you are attempting to pass what will likely compile to an int to a slot which can take either a byte or a const void*. The constant value 0x00 is convertible to both byte and const void*. Neither of these conversions is preferred and hence the compiler errors on an ambiguity.

JaredPar
Yup, that was pretty much my though.
Stringer Bell