fork download
  1. #include <memory>
  2.  
  3. class Base{};
  4. class Derived : public Base {};
  5. class ExtraDerived : public Derived {};
  6.  
  7.  
  8. bool IsBase(Base*){ return true; }
  9. bool IsBase(Derived*){ return false; }
  10.  
  11. bool IsBase(std::shared_ptr<Base>){ return true; }
  12. bool IsBase(std::shared_ptr<Derived>){ return false; }
  13.  
  14. int main()
  15. {
  16. auto derived = std::make_shared<Derived>();
  17. auto extra_derived = std::make_shared<ExtraDerived>();
  18. // works
  19. auto raw_result_derived = IsBase(derived.get());
  20. auto raw_result_extra_derived = IsBase(extra_derived.get());
  21. auto shared_result_derived = IsBase(derived);
  22. // doesn't work
  23. auto shared_result_extra_derived = IsBase(extra_derived);
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:60: error: call of overloaded ‘IsBase(std::shared_ptr<ExtraDerived>&)’ is ambiguous
prog.cpp:23:60: note: candidates are:
prog.cpp:11:6: note: bool IsBase(std::shared_ptr<Base>)
prog.cpp:12:6: note: bool IsBase(std::shared_ptr<Derived>)
prog.cpp:23:60: error: unable to deduce ‘auto’ from ‘<expression error>’
prog.cpp:19:10: warning: unused variable ‘raw_result_derived’ [-Wunused-variable]
prog.cpp:20:10: warning: unused variable ‘raw_result_extra_derived’ [-Wunused-variable]
prog.cpp:21:10: warning: unused variable ‘shared_result_derived’ [-Wunused-variable]
prog.cpp:23:10: warning: unused variable ‘shared_result_extra_derived’ [-Wunused-variable]
stdout
Standard output is empty