fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Person{
  6. string name;
  7. int age;
  8. public:
  9. Person(){
  10.  
  11. }
  12. void setPerson(string name, int age){
  13. this->name = name;
  14. this->age = age;
  15. }
  16. };
  17.  
  18. int main() {
  19. Person* friends = new Person[3];
  20.  
  21. // setting the data members
  22. friends[0].setPerson("Bob", 21);
  23. friends[1].setPerson("Alice", 19);
  24. friends[2].setPerson("Jack", 5);
  25.  
  26. // destructing my friends
  27. delete[] friends;
  28. return 0;
  29. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty