fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct GetValue{
  7. private:
  8. int beta;
  9.  
  10. public:
  11. GetValue(int beta){
  12. this->beta = beta;
  13. }
  14. int operator()(void){
  15. return beta;
  16. }
  17. };
  18.  
  19. class Base{
  20. public:
  21. int i;
  22. GetValue getValue;
  23.  
  24. Base(int i, int j):getValue(j){
  25. this->i = i;
  26. }
  27. };
  28.  
  29. int main() {
  30. const int N = 5;
  31. vector<Base*> bases;
  32.  
  33. for(int i=0; i<5; i++){
  34. bases.emplace_back(new Base(i, i*i));
  35. }
  36. for(Base* base: bases){
  37. cout << base->getValue() << endl;
  38. //cout << base->getValue.beta << endl;//NG//‘int GetValue::beta’ is private within this context
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
0
1
4
9
16