我有一些类似的代码
#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;
}
Run Code Online (Sandbox Code Playgroud)
为什么setUserName()main中的函数调用不会更改我的xxx用户名?
顺便说说:
std::array因为我想将数据保存在二进制文件中