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. using BaseClass::GetDetections;
  27. int GetDetections(const std::vector<Feature>& features) const {
  28. return 7;
  29. }
  30. };
  31.  
  32. int main() {
  33. SubClass s;
  34. std::cout << s.GetDetections("testfile.txt");
  35. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
7