Home > Back-end > No matching with specified type of overloaded function "maxn" instances
No matching with specified type of overloaded function "maxn" instances
Time:01-16
C + + primer plus chapter 8, 8.8.6, programming practice topic 6
template & lt; Typename T> Auto maxn (const T arr []) - & gt; T { Int len=sizeof (arr)/sizeof (arr [0]). T m=arr [0]; For (int I=1; I & lt; Len. I++) { If (m{ M=arr [I]; } } return m; }
Error: no matching the specified type of overloaded function "maxn" instances
CodePudding user response:
The template you write wrong, you kind of int len is not the length of the array
CodePudding user response:
template & lt; Typename T> Auto maxn (T & amp; Arr) - & gt; The decltype (arr [0]) { Int len=sizeof (arr)/sizeof (arr [0]). The decltype (arr [0]) m=arr [0]. For (int I=1; I & lt; Len. I++) { If (m{ M=arr [I]; } } return m; }
Did not have an error, the runtime problems Undefined reference to ` decltype ({1} parm# [0]) maxn (int *) ' collect2.exe: error: ld returned 1 exit status
CodePudding user response:
Array as a parameter, the sizeof (arr) will be the size of a pointer
CodePudding user response:
For this kind of the container traversal algorithms usually does not directly pass a container in the past, consider the realization of the STL, usually wear vessel head and tail, and to calculate Such as sort (begin and end, CMP)