且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么不能更改向量中的对象?

更新时间:2023-11-22 23:41:58

在您的方法中:

Tile atIndex(unsigned int row, unsigned int col) const

您应该返回对Tile的引用:

you should return a reference to Tile:

Tile& atIndex(unsigned int row, unsigned int col)

现在你正在返回副本,这就是为什么修改不工作。也不应该是 const ,否则会得到编译错误。

now you are returning copy, and that is why modifications does not work. Also it should not be const, otherwise you will get compiler error.