Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用绑定属性时BGL中存在不完整的类型错误_C++_Boost_Undefined Behavior_Boost Graph - Fatal编程技术网

C++ 使用绑定属性时BGL中存在不完整的类型错误

C++ 使用绑定属性时BGL中存在不完整的类型错误,c++,boost,undefined-behavior,boost-graph,C++,Boost,Undefined Behavior,Boost Graph,我在某些g++4.x版本上正确编译了此代码,现在版本4.6终止编译时出现错误: /usr/include/boost/pending/property.hpp:35:7: error: ‘boost::property<Tag, T, Base>::m_value’ has incomplete type /usr/include/boost/pending/property.hpp:35:7:错误:“boost::property::m_value”的类型不完整 该错误似乎是由

我在某些g++4.x版本上正确编译了此代码,现在版本4.6终止编译时出现错误:

/usr/include/boost/pending/property.hpp:35:7: error: ‘boost::property<Tag, T, Base>::m_value’ has incomplete type
/usr/include/boost/pending/property.hpp:35:7:错误:“boost::property::m_value”的类型不完整
该错误似乎是由graph_类型和edge_信息类型声明之间的循环引起的

我能够在下面几行代码中分离出问题。如何使用依赖于节点的绑定属性的类型来定义边的属性?解决方案仍应使用捆绑属性(因为许多代码依赖于此图形类型)。如何更正以下代码

#include <iostream>
#include <boost/graph/adjacency_list.hpp>

using namespace std;
using namespace boost;

template<typename map_type>
struct map_computation {
  map_type m;
};

struct vertex_info;
struct edge_info;

typedef adjacency_list<vecS, 
               vecS, 
               bidirectionalS, 
               vertex_info, 
               edge_info> graph_type;

struct position {
  double x, y;
};

struct vertex_info {
  position p;
};

typedef boost::property_map<graph_type, 
                position vertex_info::*>::type position_map_type;

struct edge_info {
  map_computation<position_map_type>* c;
};

int main(int argc, char* argv[])
{
  graph_type g;
  return 0;
}
#包括
#包括
使用名称空间std;
使用名称空间boost;
模板
结构映射计算{
map_型m;
};
结构顶点信息;
结构边缘信息;
typedef邻接列表图类型;
结构位置{
双x,y;
};
结构顶点信息{
位置p;
};
typedef boost::property_map::type position_map_type;
结构边缘信息{
map_计算*c;
};
int main(int argc,char*argv[])
{
g型图;
返回0;
}
编辑:完整的错误日志显示:

In file included from /usr/include/boost/graph/graph_traits.hpp:22:0,
                 from /usr/include/boost/graph/adjacency_list.hpp:33,
                 from gtest.cc:2:
/usr/include/boost/pending/property.hpp: In instantiation of ‘boost::property<boost::edge_bundle_t, edge_info, boost::no_property>’:
/usr/include/boost/pending/detail/property.hpp:94:48:   instantiated from ‘boost::detail::build_property_tag_value_alist<boost::property<boost::edge_bundle_t, edge_info, boost::no_property> >’
/usr/include/boost/pending/property.hpp:63:81:   instantiated from ‘boost::property_value<boost::property<boost::edge_bundle_t, edge_info, boost::no_property>, boost::edge_bundle_t>’
/usr/include/boost/graph/properties.hpp:448:63:   instantiated from ‘boost::graph_detail::retagged_bundle<boost::property<boost::edge_bundle_t, edge_info, boost::no_property>, boost::edge_bundle_t>’
/usr/include/boost/graph/properties.hpp:461:64:   instantiated from ‘boost::graph_detail::normal_property<edge_info, boost::edge_bundle_t>’
/usr/include/boost/graph/properties.hpp:473:12:   instantiated from ‘boost::graph_detail::edge_prop<edge_info>’
/usr/include/boost/graph/adjacency_list.hpp:381:70:   instantiated from ‘boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertex_info, edge_info>’
/usr/include/boost/graph/properties.hpp:418:44:   instantiated from ‘boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertex_info, edge_info>, position vertex_info::*>’
gtest.cc:30:32:   instantiated from here
/usr/include/boost/pending/property.hpp:35:7: error: ‘boost::property<Tag, T, Base>::m_value’ has incomplete type
gtest.cc:13:8: error: forward declaration of ‘struct edge_info’
gtest.cc:33:45: error: template argument 1 is invalid
在/usr/include/boost/graph/graph_traits.hpp:22:0中包含的文件中,
来自/usr/include/boost/graph/adjacence_list.hpp:33,
来自gtest.cc:2:
/usr/include/boost/pending/property.hpp:在“boost::property”的实例化中:
/usr/include/boost/pending/detail/property.hpp:94:48:从“boost::detail::build\u property\u tag\u value\u列表”实例化
/usr/include/boost/pending/property.hpp:63:81:从“boost::property_value”实例化
/usr/include/boost/graph/properties.hpp:448:63:从“boost::graph_detail::retaged_bundle”实例化
/usr/include/boost/graph/properties.hpp:461:64:从“boost::graph\u detail::normal\u property”实例化
/usr/include/boost/graph/properties.hpp:473:12:从“boost::graph\u detail::edge\u prop”实例化
/usr/include/boost/graph/adjacence_list.hpp:381:70:从“boost::adjacence_list”实例化
/usr/include/boost/graph/properties.hpp:418:44:从“boost::property\u map”实例化
gtest.cc:30:32:从此处实例化
/usr/include/boost/pending/property.hpp:35:7:错误:“boost::property::m_value”的类型不完整
gtest.cc:13:8:错误:“结构边缘信息”的正向声明
gtest.cc:33:45:错误:模板参数1无效

您不能有像这样的递归类型定义

struct edge_info;

typedef adjacency_list<..., edge_info> graph_type;

typedef boost::property_map<graph_type, ...>::type position_map_type;

struct edge_info { map_computation<position_map_type>* c; };
struct edge\u info;
typedef邻接列表图类型;
typedef boost::property_map::type position_map_type;
结构边信息{映射计算*c;};

如上面提到的,C++标准在〈7.4.3.6/2〉中指出,

特别是,在以下情况下,影响未定义:

__[…]-如果在实例化模板组件时将不完整类型(3.9)用作模板参数。 __[……]

根据你想要完成的(从你的问题不完全清楚),你可能想考虑奇怪的重复模板模式(CRTP),在其中你可以做这样的事情:

template<typename edge>
class some_graph_type 
{ // ... };

class my_edge_type
: 
    public some_graph_type<my_edge_type> 
{ // ... };
模板
给某个图类型分类
{ // ... };
给我的边分类
: 
公共图类型
{ // ... };

因此,您可以让一个
edge
类从类模板派生,并将其自身作为模板参数。类似地,您可以让一个
edge
类拥有一个
edge*
成员(类似于链表),但不是一个您需要首先了解
edge
本身的完整定义的成员。

错误是否说with Tag=…,T=…,Base=…?@K-ballo我已经在问题正文中包含了完整的错误报告。谢谢。谢谢,我以为错误是我的,而不是编译器的。尽管如此,我还是希望通过对使用graph_类型的代码进行最小的更改来解决编译错误。(顺便说一句:我无法更改boost::graph类型(这是一种boost类型),因此我不明白CRTP对我的情况有什么帮助,请解释一下。@baol正如我所解释的,如果你只有一个
edge*
作为成员类型,它就可以工作。但是如果你有一个带有
edge
作为模板参数的成员指针,它就不能工作了。@baol你刚刚撤销了“已接受”状态?请告诉我如何改进答案。@TemplateTex您详细描述了问题,但没有提供解决方案。如果需要更多上下文,请参阅boost graph library文档。