小编art*_*hur的帖子

c ++访问地图中数组的元素

可能重复:
使用数组作为映射值:无法查看错误

假设我有以下数据结构:

std::map<size_t, double[2] > trace;
Run Code Online (Sandbox Code Playgroud)

如何使用operator []访问其元素?

基本上我想做的事情如下:

trace[0][0] = 10.0;
trace[0][1] = 11.0;
Run Code Online (Sandbox Code Playgroud)

在编译这些代码行时,我收到以下错误:

/usr/include/c++/4.6/bits/stl_map.h:453:11: error: conversion from ‘int’ to non-scalar type ‘std::map<long unsigned int, double [2]>::mapped_type {aka double [2]}’ requested
Run Code Online (Sandbox Code Playgroud)

评论?

c++ arrays map

8
推荐指数
1
解决办法
2185
查看次数

c ++静态类成员的前向声明

我有一堂课:

class M {
public:
    static std::string t[];
};
Run Code Online (Sandbox Code Playgroud)

稍后进行初始化。我想稍后在不同的类(头文件)中使用 M::t:

class Use {
public:
    void f() { std::cout << M::t[0] << std::endl; }
};
Run Code Online (Sandbox Code Playgroud)

有没有办法在不包含 Use 的头文件的整个类 M 的情况下实现这一点?我知道前向声明不允许访问类成员,但是这种美是静态的,因此对于编译器来说应该不是一个大问题。

c++ forward-declaration

6
推荐指数
1
解决办法
5019
查看次数

更新表名为参数的游标记录

我正在调整一些PL/pgSQL代码,所以我refcursor可以将表名作为参数.因此我更改了以下行:

declare
 pointCurs CURSOR FOR SELECT * from tableName for update;
Run Code Online (Sandbox Code Playgroud)

这一个:

OPEN pointCurs FOR execute 'SELECT * FROM ' || quote_ident(tableName) for update;
Run Code Online (Sandbox Code Playgroud)

我调整了循环,然后,循环经过了.现在在循环中的某个时刻我需要更新记录(由光标指向)并且我卡住了.我该如何正确调整以下代码行?

UPDATE tableName set tp_id = pos where current of pointCurs;
Run Code Online (Sandbox Code Playgroud)

我修改了tableName和的引号,并在开头pos添加了EXECUTE子句,但是我得到了错误where current of pointCurs.

问题:

(i)我如何更新记录?
(ii)该函数适用于来自公共模式的表,而来自其他模式的表(例如trace.myname)失败.

任何评论都非常感谢..

postgresql dynamic-sql plpgsql cursor sql-update

6
推荐指数
1
解决办法
1万
查看次数

使用SpatialIndex库选择R*Tree的参数

我正在使用来自http://libspatialindex.github.com/的spatialindex库

我在主内存中创建一个R*树:

size_t capacity = 10;
bool bWriteThrough = false;
fileInMem = StorageManager
    ::createNewRandomEvictionsBuffer(*memStorage, capacity, bWriteThrough);

double fillFactor = 0.7;
size_t indexCapacity = 10;
size_t leafCapacity = 10;
size_t dimension = 2;
RTree::RTreeVariant rv = RTree::RV_RSTAR;
tree = RTree::createNewRTree(*fileInMem, fillFactor, indexCapacity,
   leafCapacity, dimension, rv, indexIdentifier);
Run Code Online (Sandbox Code Playgroud)

然后我插入了大量的边界框,目前大约2.5M(德国巴伐利亚州的公路网).后来我的目标是插入欧洲的所有道路.

存储管理器和rtree的参数选择有哪些?大多数情况下,我使用rtree来查找到给定查询(bbox交叉点)最近的道路.

c++ indexing spatial spatial-index r-tree

5
推荐指数
1
解决办法
637
查看次数

节俭:从 tSimpleServer 更改为 TNonblockingServer

我有一个简单的节俭服务器:

  shared_ptr<TProcessor> processor(new MyProcessor(handlerTrace));
  shared_ptr<TServerTransport>  serverTransport(new TServerSocket(port));
  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  shared_ptr<TProtocolFactory>  protocolFactory(new TBinaryProtocolFactory());

  TSimpleServer server(processor, serverTransport,
               transportFactory, protocolFactory);
Run Code Online (Sandbox Code Playgroud)

并能够与以下线路连接:

   boost::shared_ptr<TSocket> socket(new TSocket("localhost", port));
   boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
   boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

   MyClient client(protocol);
Run Code Online (Sandbox Code Playgroud)

现在我想将服务器更改为TNonblockingServer. 因此,我将服务器代码更改为以下内容:

  shared_ptr<TServerTransport>  serverTransport(new TServerSocket(port));
  shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
  TNonblockingServer server(processor,
                protocolFactory,
                port);
Run Code Online (Sandbox Code Playgroud)

客户端不变。现在服务器抱怨客户端并显示以下错误消息:

Thrift: Mon Aug 19 22:55:43 2013 TNonblockingServer: Serving on port 9990, 1 io threads.
Thrift: Mon Aug 19 22:55:43 2013 TNonblockingServer: using libevent 2.0.16-stable method epoll
Thrift: Mon Aug 19 22:55:43 2013 TNonblocking: IO …
Run Code Online (Sandbox Code Playgroud)

c++ connection thrift

4
推荐指数
1
解决办法
4899
查看次数

c ++ boost命名空间(而不仅仅是)名称快捷方式

我正在定义一个boost多索引容器:

namespace bmi = boost::multi_index;
struct DijkstraTriplet {
...
};

typedef multi_index_container <
  DijkstraTriplet,
  bmi::indexed_by<
    bmi::ordered_unique<bmi::member<DijkstraTriplet,size_t,&DijkstraTriplet::linkId> >,
    bmi::ordered_non_unique<bmi::identity<DijkstraTriplet> >
 >
> DijkstraTripletContainer;
Run Code Online (Sandbox Code Playgroud)

在某些时候,我正在填充数据,并希望扫描其中一个索引.为此我定义了一个迭代器:

DijkstraTripletContainer::nth_index<0>::type::iterator it;
Run Code Online (Sandbox Code Playgroud)

(使用旧的编译器).这令人难以置信的漫长而尴尬.为了使它更短,更可读,我添加了这些行:

#define dtt0 DijkstraTripletContainer::nth_index<0>::type
#define dtt1 DijkstraTripletContainer::nth_index<1>::type
Run Code Online (Sandbox Code Playgroud)

然后使用dtt0 :: iterator(优雅地简短,但同时又丑陋,因为用#defines表示).有没有#defines的快捷方式有更优雅的方法吗?我看起来像一样优雅

namespace bmi = boost::multi_index;
Run Code Online (Sandbox Code Playgroud)

评论?

c++ boost shortcut

1
推荐指数
1
解决办法
86
查看次数