fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. class MyClass {
  6. public:
  7. MyClass(std::string s, int i) {
  8. StringValue = s;
  9. IntValue = i;
  10. }
  11.  
  12. std::string StringValue;
  13. int IntValue;
  14. };
  15.  
  16. void addInstance(std::vector<MyClass*>& MyVector, int i) {
  17. MyClass c("", i);
  18. MyVector.push_back(&c);
  19. }
  20.  
  21. int main() {
  22. std::vector<MyClass*> MyVector;
  23. //MyClass c1("CLASS 1", 1);
  24. //MyClass c2("CLASS 2", 2);
  25. addInstance(MyVector, 1);
  26. addInstance(MyVector, 2);
  27.  
  28. //MyVector.push_back(&c1);
  29. //MyVector.push_back(&c2);
  30. std::cout << MyVector[0]->IntValue << ", " << MyVector[1]->IntValue;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
2, 2