fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class MainMenu {
  5. public:
  6. MainMenu() = default;
  7. ~MainMenu() = default;
  8.  
  9. void createAccount();
  10. };
  11.  
  12. class Account {
  13. public:
  14. Account() : firstname("John") {}
  15. ~Account() = default;
  16.  
  17. private:
  18. friend void MainMenu::createAccount();
  19. std::string firstname;
  20. };
  21.  
  22. void MainMenu::createAccount() {
  23. Account newAccount;
  24. std::cout << newAccount.firstname << '\n';
  25. }
  26.  
  27. int main() {
  28. MainMenu menu;
  29. menu.createAccount();
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
John