Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须实现一个程序,其中我有一个大小稳定的数组,并且在每个单元格中我必须放入一个 id、一个计数器和一个指针。我的问题是如何将多个元素放入 1 个数组单元格中?
像这样:
struct Cell { Cell() : id(0), counter(0), pointer() {} int id, counter; std::unique_ptr<int> pointer; }; Cell cells[100];
您可以像这样访问元素:
cells[0].id = 1; ++cells[0].counter; cells[0].pointer.reset(new int(9));