C++ - Could not deduce template argument -


i have sample code makes use of template programming, runs fine on linux. when try bring windows visual studio 12, got compile error template argument deduction. here fraction of code cause error:

template <int i> class assign_array { public:     template <typename u, unsigned n>     static inline void run(improved_builtin<u, n>& a, const u b[n])     {         // sth     } };  template <template <int> class a, int i, int e> struct loop_iter {     template <typename u, typename v>     static inline void iter(u& a, v& b)     {        a<i>::run(a, b); // error here     } };  template <typename t, unsigned n> improved_builtin<t, n>::improved_builtin(const t v[n]) {     loop_iter<assign_array, 0, n - 1>::iter(*this, v);     return; } 

the error occurs @ a::run(a, b) => assign_array<0>::run(improved_builtin &,const u [n])' : not deduce template argument 'const u [n]' 'const int *'

and have noticed strange in error message improved_builtin. in assign_array class, signature of first argument should improved_builtin. have no idea why appears there. has idea error?

when pass array in function decay pointer, lose size trying deduce template argument from. passing array reference preserve type , allow deduction take place:

static inline void run(improved_builtin<u, n>& a, const u (&b)[n]) //                                       take reference ^ 

the reason g++ (and clang) able compile example anyway use improved_builtin argument deduce type of u , value of n instead of array type. reason vs2012 doesn't , tries deduce array, isn't valid because has decayed. if didn't have improved_builtin argument, example wouldn't compile @ all.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -