小编lh8*_*h84的帖子

C++ - 返回C++ 11 std :: array

我有一些类似的代码

#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因为我想将数据保存在二进制文件中
  • 在我的实际代码中,我用户char [],而不是字符串

c++ arrays reference c++11

3
推荐指数
1
解决办法
4510
查看次数

标签 统计

arrays ×1

c++ ×1

c++11 ×1

reference ×1