C++ - Return C++11 std::array

Viewed 9892

I have some code like that

#define SIZE 10
Class User
{
public:
    std::array<Account, SIZE> getListAccount()
    {
         return listAccount;
    }
private:
    std::array<Account, SIZE> listAccount
}

Class Account
{
public:
    void setUserName(std::string newUSN)
    {
        userName=newUSN;
    }
private:
    string userName;
    string password;
}


int main()
{
     User xxx(.......);
     xxx.getListAccount()[1].setUserName("abc");    // It doesn't effect
     return 0;
}

Why doesn't the setUserName() function call in main change the name in my xxx User?

By the way:

  • I'm using std::array because I want to save data in binary file
  • In my actual code, I user char [], not string
2 Answers
Related