Guest User

Untitled

a guest
Aug 18th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. C Ambiguous call to overloaded function
  2. inline void MySafeStrncpy(char *strDest,size_t maxsize,const char *strSource)
  3. {
  4. if(maxsize)
  5. {
  6. maxsize--;
  7. strncpy(strDest,strSource,maxsize);
  8. strDest[maxsize]=0;
  9. }
  10. }
  11.  
  12. inline void MySafeStrncpy(char *strDest,size_t maxDestSize,
  13. const char *strSource, size_t maxSourceSize)
  14. {
  15. size_t minSize=(maxDestSize<maxSourceSize) ? maxDestSize:maxSourceSize;
  16. MySafeStrncpy(strDest,minSize,strSource);
  17. }
  18.  
  19. template <size_t size>
  20. void MySafeStrncpy(char (&strDest)[size],const char *strSource)
  21. {
  22. MySafeStrncpy(strDest,size,strSource);
  23. }
  24.  
  25. template <size_t sizeDest,size_t sizeSource>
  26. void MySafeStrncpy(char (&strDest)[sizeDest],
  27. const char (&strSource)[sizeSource])
  28. {
  29. MySafeStrncpy(strDest,sizeDest,strSource,sizeSource);
  30. }
  31.  
  32. template <size_t sizeSource>
  33. void MySafeStrncpy(char *strDest,size_t maxDestSize,
  34. const char (&strSource)[sizeSource])
  35. {
  36. MySafeStrncpy(strDest,maxDestSize,strSource,sizeSource);
  37. }
  38.  
  39. char threadname[16];
  40. MySafeStrncpy(threadname,"MainThread");
  41.  
  42. error C2668: 'MySafeStrncpy' : ambiguous call to overloaded function
  43. > could be 'void MySafeStrncpy<16,11>(char (&)[16],const char (&)[11])'
  44. > or 'void MySafeStrncpy<16>(char (&)[16],const char *)'
  45. > while trying to match the argument list '(char [16], const char [11])'
  46.  
  47. template <size_t size>
  48. void MySafeStrncpy(char (&strDest)[size],const char *strSource)
  49.  
  50. template <size_t size, class T>
  51. void MySafeStrncpy(char (&strDest)[size], T strSource)
  52.  
  53. MySafeStrncpy(threadname,"MainThread");
  54.  
  55. MySafeStrncpy(threadname, sizeof threadname, "MainThread");
Add Comment
Please, Sign In to add comment