【发布时间】:2020-04-19 15:20:33
【问题描述】:
我目前正在完成一项大学作业,现在我正在努力解决向量问题。
我应该返回一个对象的唯一 ID,然后将该对象添加到向量中。
对象是一个结构体,定义如下:
struct VertexPuller{
std::vector<InVertex> head_settings;
std::vector<IndexType> indexing;
};
我要推送的向量是:
std::vector<std::unique_ptr<VertexPuller>> vertex_puller_tables;
我写的函数是这样的:
auto vertex_puller= std::make_unique<VertexPuller>;
auto vp_id = reinterpret_cast<VertexPullerID>(vertex_puller);
vertex_puller_tables.push_back(std::move(vertex_puller));
return vp_id;
但是在倒数第二行,当我尝试将顶点拉出器推入向量时,我收到错误 - No matching member function for call to 'push_back'。。 p>
我已经被困在这个问题上很长一段时间了,我不知道是什么原因造成的,可能是指针,就像 C 和我一样。 感谢您的建议!
【问题讨论】:
-
reinterpret_cast<VertexPullerID>(vertex_puller)- 你觉得这有什么作用?你是reinterpret_caststd::unique_ptr到你的VertexPullerID班级。
标签: c++ pointers vector graphics vertex