I am trying to play around with type deduction in templates in c++. I am experimenting with type deduction for array arguments, with the following code:
template <typename T, std::size_t N>
constexpr std::size_t func(T (&)[N]) {
return N;
}
This will simply return the length of the input array, Like So:
char arr[] = "abc";
cout << func(arr) << endl; // would print 3.
But when I modify the code of func
to have an argument name, all hell is breaking loose!
template <typename T, std::size_t N>
constexpr std::size_t func(T (&)[N] arr) {
return N;
}
The main error I am getting seems to be this : Severity Code Description Project File Line Suppression State Error (active) E1097 unknown attribute "no_init_all" ProjectName C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winnt.h 7597
Any Idea on what this issue is? and how to resolve it?
Clearly I don't need to declare the name for the parameter since I don't need to use it in this function, but just wondering why this error is popping up!
Aucun commentaire:
Enregistrer un commentaire