我在匿名命名空间中有一个全局变量.
namespace {
std::unordered_map<std::string, std::string> m;
}
A::A() { m.insert(make_pair("1", "2")); } // crasches
void A::insert() { m.insert(make_pair("1", "2")); } // ok
Run Code Online (Sandbox Code Playgroud)
如果尝试使用map构造函数内部,我会获得Access违规读取位置.但如果我A在初始化之后使用它就可以了.
这种行为是否正确?
我在确定 的位置时遇到问题QGraphicsLineItem。我想相对地移动场景中的物品,所以我需要知道它们的位置。我的QGraphicsPixmapItem对象很少,我对它们没有问题,因为pixmapItem.pos()在场景坐标中给了我每个项目的真实位置。但是使用 QGraphicsLineItemsi 为每条线获得相同的坐标 (0,0)。这是代码:
QGraphicsLineItem*line = new QGraphicsLineItem();
scene->addItem(line);
line->setLine(QLineF(0,VVR-i*(OH),HVR,VVR-i*(OH)));
Run Code Online (Sandbox Code Playgroud)
此代码在正确的位置绘制线条,但其坐标设置为(0,0)not (0,VVR-i*(OH))。
当订单项到达大于 VVR 的位置时,以下代码应将订单项移动 (VVR + OH)。但是由于所有行都有起始位置 (0,0),所以无论我把它们放在哪里,所有行都会同时移动。
QPointF current_pos = line->pos();
if (current_pos.y() >= VVR)
{
line->setPos(current_pos.x(),current_pos.y()-(VVR+(OH)));
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到 的真实(场景)坐标QGraphicsLineItem,因为我得到了QGraphicsPixmapItem谢谢!
我有一个 generic_connection
class generic_connection: public boost::enable_shared_from_this<generic_connection>
Run Code Online (Sandbox Code Playgroud)
现在我想继承它并创建
class agent_connection: public generic_connection
Run Code Online (Sandbox Code Playgroud)
确实agent_connection需要boost::enable_shared_from_this<agent_connection>再次衍生出来吗?
我想获得从点(t)到线段的垂直距离(p, q)。垂线不能与线相交[p, q]。在这种情况下,我想(p, q)假设地延长线,然后绘制垂直线以获得距离。p、q、t 都是 gps 坐标。我正在使用增强几何。
typedef boost::geometry::model::point<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::segment<geo_point> geo_segment;
geo_point p(88.41253929999999, 22.560206299999997);
geo_point q(88.36928063300775, 22.620867969497795);
geo_point t(88.29580956367181, 22.71558662052875);
Run Code Online (Sandbox Code Playgroud)
我在地图上标出了这三个位置

我衡量两个距离qt从和距离t来pq
double dist_qt = boost::geometry::distance(q, t);
std::cout << dist_qt*earth_radius << std::endl;
geo_segment line(p, q);
double perp_dist = boost::geometry::distance(t, line);
std::cout << perp_dist*earth_radius << std::endl;
Run Code Online (Sandbox Code Playgroud)
这两个距离是相同的。这意味着它不计算垂直距离。相反,它计算了shortest从一个点到一条线的距离bounds。
如何以这种方式计算垂直距离,使其无论边界如何都必须垂直?
cpp.sh 中的工作示例
我要比较4个变量,a,b,c,d如果它们中的任何一个-1返回false.这可能是多么简洁?可能是一些数学运算可以做!! 我不喜欢为这个简单的事情浪费这么多的字符或线条.
下面的代码正在给出错误,w_add_ax_extra(1, 'k', 'v')之前w_add_ax_extra(some_id, kv.k, kv.v)我将其更改k, v为重现相同的错误
declare
kv record;
begin
-- Lines skipped
for kv in select * from (select (each(extras)).*) as f(k,v) loop
raise notice 'key=%,value=%',kv.k,kv.v;
w_add_ax_extra(1, 'k', 'v');
end loop;
-- Lines Skipped
end
Run Code Online (Sandbox Code Playgroud)
我收到语法错误但无法理解我错过了什么
ERROR: syntax error at or near "w_add_ax_extra"
LINE 1: w_add_ax_extra(1, 'k', 'v')
Run Code Online (Sandbox Code Playgroud)
但是如果我这样做的dummy = w_add_ax_extra(1, 'k', 'v')话.是的,这个函数返回一个整数.但我不需要在这里存储它.是否必须保留返回值?
这是我尝试过的,但我被Error: Unknown exception抛出了
try{//load
std::ifstream stream(arch_name.c_str());
std::cout << ">> " << "Started deserializing " << arch_name << std::endl;
boost::archive::binary_iarchive arc(stream);
arc & c & matrix;
stream.close();
std::cout << ">> " << "Finished deserializing" << std::endl;
}catch(std::exception e){
std::cout << "Error: " << e.what() << std::endl;
return 1;
}
Run Code Online (Sandbox Code Playgroud)
这在使用gcc的Linux中运行良好.我在Windows中使用Visual Studio.
backtrace显示basic_binary_iprimitive.hpp正在抛出异常
template<class Archive, class Elem, class Tr>
inline void basic_binary_iprimitive<Archive, Elem, Tr>::load_binary( void *address, std::size_t count){
//.....
if(scount != s)
boost::serialization::throw_exception(
archive_exception(archive_exception::input_stream_error)
);
Run Code Online (Sandbox Code Playgroud)
我改变了 …
c++ ×4
boost ×2
boost-asio ×1
c ×1
c++11 ×1
coding-style ×1
exception ×1
geometry ×1
gis ×1
math ×1
plpgsql ×1
postgresql ×1
qt ×1
shared-ptr ×1
weak-ptr ×1
xor ×1