[英]reference_wrapper cause “incomplete type is not allowed”
#include <vector>
#include <array>
int main() {
typedef std::array<int,2> point;
typedef std::vector<std::reference_wrapper<point>> route;
std::vector<std::vector<point>> lattice = {
{point{ {0,0} },point{ {0,1} }},
{point{ {1,0} },point{ {1,1} }}
};
route r = {&lattice[0][0],&lattice[0][1]};
point last = r.back().get();
}
The last line won't compile because "incomplete type is not allowed".最后一行不会编译,因为“不允许不完整的类型”。 When I search on internet, a paper seems to address this problem: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0357r3.html .
当我在互联网上搜索时,一篇论文似乎解决了这个问题: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0357r3.html 。 That paper is just above my level.
那篇论文刚好在我的水平之上。 So I am not sure.
所以我不确定。 Would anyone give a confirmation or a solution to this problem?
有人会确认或解决此问题吗?
Also, workarounds are appreciated:此外,解决方法表示赞赏:
I am trying to store routes on a not-so-large lattice.我正在尝试将路线存储在不太大的格子上。 There will be a lot of routes (dense in the lattice).
会有很多路线(格子密集)。 So, I am thinking, within a route, store reference of points instead of points in order to save memory.
所以,我在想,在一条路线中,存储点而不是点的参考以保存 memory。
You must #include <functional>
before using std::reference_wrapper
.您必须在使用
std::reference_wrapper
之前#include <functional>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.