vendredi 19 janvier 2018

Prevent Array Decay for overloaded functions taking const char* or const char(&)[] [duplicate]

This question already has an answer here:

Given the following functions

void DoSomething(const char* str) {

}

and

template<size_t N>
void DoSomething(const char(&str)[N]) {

}

Is there a way to prevent my arrays from 'decaying' to the (const char*) overload?

The function is invoked in the following fashion but it seems to take preference to the non-templated function.

DoSomething("Beep Boop");

I've found I can invoke the templated function by explicitly providing a value for the templated argument. I would like to not do this if possible.

DoSomething<10>("Beep Boop");

Aucun commentaire:

Enregistrer un commentaire