fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Base {
  6. //no visitbility means private, not visible for derived
  7. protected: // this is visible for derived, but not for outsiders
  8. int x, y;
  9. public: // this is visible for everyone
  10. virtual void readDataFromStream(istream&);
  11. };
  12.  
  13. void Base::readDataFromStream(istream& is) {
  14. //insert values from stream into attributes
  15. is >> x;
  16. is >> y;
  17. cout <<"done-";
  18. }
  19.  
  20. class Derived : Base { // no inheritance visibility: outside world don't have access to base pubic members
  21. // if you want benefit from inheritance, make it Derived: public Base
  22. //declaration
  23. //method inherited from Base
  24. int z;
  25. public:
  26. void readDataFromStream(istream&) override;
  27.  
  28. //definition - overrides definition in Base
  29. //function called from inside function that passes file data into stream
  30. //- stream already contains data
  31. };
  32.  
  33. void Derived::readDataFromStream(istream& is) {
  34. //insert values from stream into attributes
  35. Base::readDataFromStream(is);
  36. is >> z;
  37. cout << "yes";
  38. }
  39.  
  40.  
  41.  
  42. int main() {
  43. // your code goes here
  44. Derived d;
  45.  
  46. d.readDataFromStream(cin);
  47. return 0;
  48. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
done-yes