gpt4 book ai didi

c++ - 在 Lemon Graph Library 中制作图形 vector

转载 作者:行者123 更新时间:2023-11-28 03:15:02 27 4
gpt4 key购买 nike

我创建了一个图并在 Lemon Graph Library 中添加了节点和转换

typedef ListDigraph Graph;
vector<Graph> Process;
for(temp = temp.child("role");temp;temp = temp.next_sibling("role"))
{
Graph proc;
for(xml_node temp1 = temp.child("states").child("state");temp1;temp1 = temp1.next_sibling())
{
string state = temp1.child_value();
state = role + "_" + state;
vertex = process.addNode();
state_name[vertex] = state;
}
Process.push_back(proc);
}

如果我不将其推送到 vector 中,一切正常,但当我尝试将其推送到 Process 时,我会收到错误消息。错误是 70-80 行长,但我发现的要点是:

/usr/local/include/lemon/list_graph.h:336:5: error:
lemon::ListDigraph::ListDigraph(const lemon::ListDigraph&) is private

按照@Magtheridon96 的建议进行操作后出现以下错误:

    In file included from /usr/include/c++/4.6/i686-linux-gnu/./bits/c++allocator.h:34:0,
from /usr/include/c++/4.6/bits/allocator.h:48,
from /usr/include/c++/4.6/string:43,
from /usr/include/c++/4.6/bits/locale_classes.h:42,
from /usr/include/c++/4.6/bits/ios_base.h:43,
from /usr/include/c++/4.6/ios:43,
from /usr/include/c++/4.6/ostream:40,
from /usr/include/c++/4.6/iostream:40,
from usingleda.cpp:1:
/usr/include/c++/4.6/ext/new_allocator.h: In member function ‘void __gnu_cxx::new_allocator<_Tp>::construct(__gnu_cxx::new_allocator<_Tp>::pointer, _Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, __gnu_cxx::new_allocator<_Tp>::pointer = std::unique_ptr<lemon::ListDigraph>*]’:
/usr/include/c++/4.6/bits/vector.tcc:97:6: instantiated from ‘void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, _Alloc = std::allocator<std::unique_ptr<lemon::ListDigraph> >]’
usingleda.cpp:134:43: instantiated from here
/usr/include/c++/4.6/ext/new_allocator.h:114:4: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = lemon::ListDigraph, _Dp = std::default_delete<lemon::ListDigraph>, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<lemon::ListDigraph>]’
/usr/include/c++/4.6/bits/unique_ptr.h:256:7: error: declared here
In file included from /usr/include/c++/4.6/vector:70:0,
from /usr/local/include/lemon/core.h:22,
from /usr/local/include/lemon/list_graph.h:26,
from usingleda.cpp:3:
/usr/include/c++/4.6/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, _Alloc = std::allocator<std::unique_ptr<lemon::ListDigraph> >, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::unique_ptr<lemon::ListDigraph>*, std::vector<std::unique_ptr<lemon::ListDigraph> > >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = std::unique_ptr<lemon::ListDigraph>*]’:
/usr/include/c++/4.6/bits/vector.tcc:102:4: instantiated from ‘void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, _Alloc = std::allocator<std::unique_ptr<lemon::ListDigraph> >]’
usingleda.cpp:134:43: instantiated from here
/usr/include/c++/4.6/bits/vector.tcc:319:4: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = lemon::ListDigraph, _Dp = std::default_delete<lemon::ListDigraph>, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<lemon::ListDigraph>]’
/usr/include/c++/4.6/bits/unique_ptr.h:256:7: error: declared here

最佳答案

你不能复制这个对象(这是作者想要的)。该库的作者将复制构造函数设为私有(private),以确保您不能这样做。

解决办法是改成std::vector<Graph>std::vector<std::unique_ptr<Graph>>

这样一来,您就不需要按照作者的意图制作对象的拷贝。

然后你会像这样分配和插入:

std::unique_ptr<Graph> graph(new Graph);
// ...
vec.emplace_back(graph);

关于c++ - 在 Lemon Graph Library 中制作图形 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17170866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com