c++ - MSVC 2015 SFINAE Failing To Find Proper Member Function -
using msvc 2015, have basic code follows:
class setter { public: void set(int value) {} template <int size> void set(int value[size]) {} };
it doesn't seem matter setters do, left them blank. however, if attempt use array version of set
follows:
int data[128]; setter setter; setter.set(data);
i receive following compile-time error:
error c2664 : 'void setter::set(int)' : cannot convert argument 1 'int [128]' 'int'
according rules of sfinae, shouldn't there exist member function signature matches setter
class? template set
, seems, should match along lines of template<> void setter::set(int value[128]) {}
can deduced. there rule prohibits code compiling in standard, or msvc doing wrong? thanks!
edit
really, need solution here. if can't point me answer in standard knows work around, i'm receptive that.
solution:
template <int size> void set(int (&value)[size]) {}
you can't pass simple int array value, should (by ref).
if want pass array value, consider using std::array
Comments
Post a Comment