fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. struct Feature {
  6. float x;
  7. float y;
  8. float value;
  9. };
  10.  
  11. class BaseClass {
  12. public:
  13. int GetDetections(const std::string& filename) const {
  14. // Normally, I'd read in features from a file, but for this online
  15. // example, I'll just construct an feature set manually.
  16. std::vector<Feature> features;
  17. return GetDetections(features);
  18. };
  19. // Pure virtual function.
  20. virtual int GetDetections(const std::vector<Feature>& features) const = 0;
  21. };
  22.  
  23. class SubClass : public BaseClass {
  24. public:
  25. // Giving the pure virtual function an implementation in this class.
  26. int GetDetections(const std::vector<Feature>& features) const {
  27. return 7;
  28. }
  29. };
  30.  
  31. int main() {
  32. SubClass s;
  33. std::cout << s.GetDetections("testfile.txt");
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:33:48: error: no matching function for call to ‘SubClass::GetDetections(const char [13])’
prog.cpp:33:48: note: candidate is:
prog.cpp:26:9: note: virtual int SubClass::GetDetections(const std::vector<Feature>&) const
prog.cpp:26:9: note:   no known conversion for argument 1 from ‘const char [13]’ to ‘const std::vector<Feature>&’
stdout
Standard output is empty