- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试从 BGL 开始,这意味着我从很多 typedef 开始:
#include <iostream> //std::cin, std::cout
#include <tuple> //std::tie
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
typedef adjacency_list<vecS,vecS,undirectedS,no_property,property<edge_weight_t,int> > Graph;
typedef graph_traits<Graph> Traits;
typedef Traits::vertex_descriptor Vertex;
typedef Traits::edge_descriptor Edge;
typedef property_map<Graph, edge_weight_t>::type EdgeWeightMap; //::type necessary (why?)
int main(int argc, char* argv[]){
int n = ...;
Graph g(n);
EdgeWeightMap weight_of;
Edge e;
bool success;
int s,t,w;
std::cin >> s >> t >> w;
tie(e,success) = add_edge(s,t,g);
if(success)weight_of[e] = w;
}
我想知道为什么 ::type
在 EdgeWeightMap
的类型定义中是必要的。如果我省略它,我会得到
error: no match for ‘operator[]’ (operand types are
‘EdgeWeightMap {aka boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int> >, boost::edge_weight_t>}’
and
‘Edge {aka boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>}’
) weight_of[e] = w;
(对格式感到抱歉,typedefs 的 <
和 >
似乎干扰了 block 引用)
确实,当我尝试
EdgeWeightMap weight_of = get(edge_weight,g);
我得到一个
error: conversion from
‘boost::detail::adj_list_any_edge_pmap::bind_<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int> >, boost::property<boost::edge_weight_t, int>, boost::edge_weight_t>::type {aka boost::adj_list_edge_property_map<boost::undirected_tag, int, int&, unsigned int, boost::property<boost::edge_weight_t, int>, boost::edge_weight_t>}’
to non-scalar type
‘EdgeWeightMap {aka boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int> >, boost::edge_weight_t>}’
requested EdgeWeightMap weight_of = get(edge_weight,g);
现在,我可以看到这些是不同的类型,但我不明白的是为什么它们不同。由于我有点想避免意外,有人可以告诉我什么时候 ::type
是必需的,什么时候不能使用?
最佳答案
来自阅读property_map文档中,“property_map”模板旨在提供类型,而不是类型。 property_map 结构恰好包含两种类型。 type
和 const_type
,分别用于可变类型和不可变类型。
关于C++ typedef 需要::type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33056430/
我想“创建”一个类型“my_type”,它是一个 std_logic_vector(...),就像这个 C/VHDL 假代码: typedef std_logic_vector(CONSTANT do
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我已阅读说明,我明白它是一个函数类型别名。 typedef 或函数类型别名为函数类型提供一个名称,您可以在声明字段和返回类型时使用该名称。当将函数类型分配给变量时,typedef 会保留类型信息。 h
Vala 是否有能力做一些类似于 C 中的 typedef 或 D 中的 alias 的事情?我检查了它的零星文档,但找不到与此相关的任何内容。 最佳答案 不是 typedef 本身,但您可以扩展大多
我对这段代码有一些问题: typedef struct Product { char product_code[5]; int sells; int sells_quantit
我对书中的代码有疑问: const int SQUARE_ARRAY_SIZE = 4; const int SQUARE_INFO_SIZE = 4; typedef Square SquareAr
typedef经常像这样工作:typedef .但是函数指针的 typedef 似乎有不同的结构:typedef int (*fn)(char *, char *); - 没有类型别名,只有一个函
我被分配去处理一些代码,但我事先得到了一部分。它包括这部分代码: typedef int ElementType; struct Node; typedef struct Node *PtrToNod
我正在尝试创建通用容器包装器。 template class ContainerWrapper { public: using allocator_type = typename type::al
抱歉,标题太长了。 我在类列表中有一个 typedef: template class List { // Think of a class Iter_ with ListElem *pCu
我想制作一个 typedef,它依赖于模板参数中 typedef 的存在: struct foo { using MyType = int; }; template struct bar {
出于教育目的,我正在查看 Eigen 源代码。我注意到对于每个具体类模板 X在层次结构中,有一个 internal::traits定义。一个典型的例子可以在 Matrix.h 中找到: namespa
假设我有三个文件 //first.h typedef typename std::map MapVertexVd_t; //the graph class and ... //other useful
如果我需要 Swift 中的自定义类型,我可以 typedef,我该怎么做? (类似于闭包语法 typedef) 最佳答案 关键字typealias用于代替typedef: typealias Cus
由于标题可能看起来很困惑,让我举个例子: typedef bool foo[2]; typedef foo bar[4]; bar what_am_i; 所以,我认为 what_am_i 是 [4][
我想声明一个 typedef,像这样: 指向另一个 typedef 的任何数组的指针。 例如: 类型定义 1: typedef struct { int a; }structA_t1; 类型定
要将 my_int 声明为 int 的类型别名,我们可以这样写: typedef int my_int; // (1) 奇怪的是,以下内容似乎也定义了 int 别名: int typedef my
如何在其他 typedef struct 中声明 typedef struct? typedef struct { char* type; char* destination;
我正在尝试将 malloc'd ptr 保存在全局 ptr 中,以便我可以在另一个函数中使用它。理想情况下,我希望在全局范围内有一个更智能的数据结构,但现在我只是想让全局 ptr 工作。 在我的 lw
MachineState machine; ControlSignals theControls = machine.control_signals; //Why is this giving an
我是一名优秀的程序员,十分优秀!