fork download
  1. #include <iostream>
  2.  
  3. struct Spec {
  4. Spec(int age_, int income_) : age(age_), income(income_) {}
  5.  
  6. int age;
  7. int income;
  8. };
  9.  
  10. std::ostream& operator << (std::ostream& os, const Spec& spec) {
  11. return os << "年齢:" << spec.age << " 年収:" << spec.income;
  12. }
  13.  
  14. class Ore {
  15. public:
  16. Ore() : spec_(23, 0) {}
  17. void export_spec() const {
  18. std::cout << "俺のスペック " << spec_ << std::endl;
  19. }
  20.  
  21. int* age_ptr() { return &spec_.age; }
  22. int* income_ptr() { return &spec_.income; }
  23.  
  24. private:
  25. Spec spec_;
  26. };
  27.  
  28. int main() {
  29. Ore ore;
  30.  
  31. ore.export_spec();
  32.  
  33. *ore.age_ptr() = 30;
  34. *ore.income_ptr() = 10000000;
  35. ore.export_spec();
  36. }
  37.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
俺のスペック 年齢:23 年収:0
俺のスペック 年齢:30 年収:10000000