fork download
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. T difference( T a, T b )
  5. {
  6. return std::abs(a - b);
  7. }
  8.  
  9. class foo_type{};
  10. foo_type operator-(foo_type, foo_type)
  11. {
  12. return foo_type();
  13. }
  14.  
  15. foo_type abs(foo_type)
  16. {
  17. return foo_type();
  18. }
  19.  
  20. int main() {
  21.  
  22. foo_type a,b;
  23. foo_type c = difference(a,b);
  24.  
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:11: warning: variable ‘c’ set but not used [-Wunused-but-set-variable]
  foo_type c = difference(a,b);
           ^
prog.cpp: In instantiation of ‘T difference(T, T) [with T = foo_type]’:
prog.cpp:23:29:   required from here
prog.cpp:6:26: error: no matching function for call to ‘abs(foo_type)’
     return std::abs(a - b);
                          ^
prog.cpp:6:26: note: candidates are:
In file included from /usr/include/c++/4.8/cstdlib:72:0,
                 from /usr/include/c++/4.8/ext/string_conversions.h:41,
                 from /usr/include/c++/4.8/bits/basic_string.h:2815,
                 from /usr/include/c++/4.8/string:52,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/stdlib.h:770:12: note: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
/usr/include/stdlib.h:770:12: note:   no known conversion for argument 1 from ‘foo_type’ to ‘int’
In file included from /usr/include/c++/4.8/ext/string_conversions.h:41:0,
                 from /usr/include/c++/4.8/bits/basic_string.h:2815,
                 from /usr/include/c++/4.8/string:52,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/cstdlib:166:3: note: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
/usr/include/c++/4.8/cstdlib:166:3: note:   no known conversion for argument 1 from ‘foo_type’ to ‘long int’
/usr/include/c++/4.8/cstdlib:174:3: note: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
/usr/include/c++/4.8/cstdlib:174:3: note:   no known conversion for argument 1 from ‘foo_type’ to ‘long long int’
prog.cpp: In function ‘T difference(T, T) [with T = foo_type]’:
prog.cpp:7:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty