I'm having trouble figuring out how to solve a compiler error I'm running into. I've reduced it down to this simplest-case representation:
enum EAtomId { EAtomId_Test };
int StringFormat(char* o_dest, size_t i_destSizeChars, const char* i_format, ...);
template <size_t SIZE>
int StringFormat(char (&o_dest)[SIZE], EAtomId i_format, ...);
void func()
{
char textBuffer[1000];
StringFormat(textBuffer, EAtomId_Test, "hi there");
}
The compiler error is:
repro.cpp(17) : error C2666: 'StringFormat' : 2 overloads have similar conversions
C:\Users\sbilas\Desktop\repro.cpp(9): could be 'int StringFormat(char *,size_t,const char *,...)'
while trying to match the argument list '(char [1000], EAtomId, const char [9])'
That's the full error btw. I'm a little surprised it isn't listing both available versions..
I have a couple problems with this error. First, I don't see why it's ambiguous. Shouldn't the compiler see the char(&)[] version as the obvious case to match? And second, how can I prevent that enum from being converted to a size_t when it's doing the lookup? Seems like I'm running into some very specific C++ rules here.
The easiest workaround for me is to put the size_t for the buffer size in front of the actual buffer. But that will break all of our conventions where we put buffer then size in our code. Is there another way to do this?
This is on VC++ 2005 btw but it reproduces on a couple other compilers I have (this is in a cross-platform game).