#include <iostream>
using namespace std;
template <typename VAR, unsigned int N>
int size(VAR (&arr)[N])
{
return sizeof(arr) / sizeof(arr[0]);
}
int main()
{
cout << size("Test"); //This is working
int x[] = {7, 5, 43, 8};
cout << endl
<< size(x); //And this works too
cout << endl
<< size({7, 9, 7, 9}); //When i try this its give me "no matching function for call to 'size'" error
return 0;
}
Parameter takes strings and arrays that modified outside the parameter. but i need to write the array directly inside the function like the code above. size({some integers});
error.size({7, 9, 7, 9}), the argument{7, 9, 7, 9}is an rvalue.Ninstead ofsizeof(arr) / sizeof(arr[0])