草庐IT

samba_share

全部标签

c++ - OpenCV: "libopencv_core.so.2.3: cannot open shared object file: No such file or directory"

我刚刚在我的Debian机器上安装了OpenCV,但遇到了一些问题。我遵循了Wiki上的安装指南。尝试编译示例给出了似乎是成功的编译,但是尝试运行它们最终会抛出错误:fagg@hubble:~/src/OpenCV-2.3.1/samples/cpp$g++-Wallem.cpp-lopencv_core-lopencv_imgproc-lopencv_calib3d-lopencv_video-lopencv_features2d-lopencv_ml-lopencv_highgui-lopencv_objdetect-lopencv_contrib-lopencv_legacyfa

c++ - 带有模板的 shared_ptr

如果我想创建一个指向结构的智能指针,我会这样做:structA{intvalue;};typedefboost::shared_ptrA_Ptr;所以,我可以这样写:A_PtrpA0(newA);pA0->value=123;但是,如果我有这样的模板结构:templatestructB{Tvalue;};我想写以下内容:B_PtrpB0(newB);pB0->value='w';那么,我应该如何声明B_Ptr呢? 最佳答案 应该是typedefshared_ptr>B_Ptr;B_Ptrp(newB);p->value='w';

c++ - 复制 boost::shared_ptr

typedefboost::shared_ptrdata_ptr;data_ptrcached_ptr;//classmemberboolsomeWork(data_ptr&passed_ptr){//mustcopypassed_ptr=cached_ptrundersomeconditions//withoutpointingatthesamememory//IsawsomewherethatIshoulddo//passed_ptr.reset(newSomeData(???))//Idon'thavea"reset"onpassed_ptr}我查看了文档;复制和转换构造函数sh

c++ - shared_ptr 的神秘崩溃

有人可以解释为什么在退出内部作用域时以下内容会在main()中崩溃吗?我正在使用VisualStudio2013。虽然GCC4.8.1一切正常,但我怀疑代码中有问题。我就是不明白。#include#includeclassPerson;classPersonProxy;classPersonInterface{public:virtual~PersonInterface()=default;virtualPersonProxy*getProxy()const=0;virtualvoidcreateProxy(Person*)=0;};classPerson:publicPersonIn

c++ - 手动递增和递减 boost::shared_ptr?

有没有办法在C++中手动增加和减少shared_ptr的计数?我要解决的问题如下。我正在用C++编写一个库,但接口(interface)必须是纯C语言。在内部,我想使用shared_ptr来简化内存管理,同时保留通过C接口(interface)传递原始指针的能力。当我通过接口(interface)传递原始指针时,我想增加引用计数。然后客户端将负责调用一个函数,该函数将在不再需要传递的对象时减少引用计数。 最佳答案 也许您正在跨DLL边界使用boost::shared_ptr,这将无法正常工作。在这种情况下boost::intrusi

c++ - 为什么 std::shared_ptr 从基类和派生类调用析构函数,而 delete 只调用基类的析构函数?

这个问题在这里已经有了答案:Howisitpossible(ifitis)toimplementshared_ptrwithoutrequiringpolymorphicclassestohavevirtualdestructor?(3个答案)关闭8年前。为什么在使用std::shared_ptr释放时从基类和派生类调用析构函数,而第二个示例仅从基类调用析构函数?classBase{public:~Base(){std::coutsharedA(newDerived);}std::cout输出:--------------------DeriveddestructorBasedestr

c++ - 如何在没有多余 RC 操作的情况下在派生类中使用 shared_from_this?

如果我想创建一个shared_ptr在从基类继承的层次结构中的派生类成员函数中,我可以使用shared_from_this和static_pointer_cast:classBase:publicstd::enable_shared_from_this{};classDer:publicBase{public:std::shared_ptrmake_SP_to_Me(){returnstd::static_pointer_cast(shared_from_this());}};我担心的是static_pointer_cast通过lvalue-ref-to-const接受它的参数,所以当

c++ - 来自同一个 enable_shared_from_this 实例的两个 shared_ptr

鉴于这个类是enable_shared_from_this:classconnection:publicstd::enable_shared_from_this{//...};假设我从sameconnection*创建了两个std::shared_ptr实例,如下所示:std::shared_ptrrc(newconnection);std::shared_ptrfc(rc.get(),[](connectionconst*c){std::cout到目前为止一切正常,因为资源{connection*}由单个shared_ptr—rc准确地说,fc只是有一个假的删除器。之后,我这样做:a

c++ - 我的 API 函数应该采用 shared_ptr 还是 weak_ptr

我目前正在设计一个API,我不确定我的函数是否应该采用shared_ptr或weak_ptr.有包含查看器的小部件。观众有一个功能add_painter这给观众增加了一个画家。当查看器需要重新绘制时,它会使用其绘制器绘制到缓冲区中并显示结果。我得出的结论是观众应该使用weak_ptr捕获画家:一个画家可能被多个观众使用,所以观众不能拥有画家。删除画家应该将其从查看器中删除。这样,用户就不需要记住他们必须调用remove_painter。功能。可能有不同类型的查看器,因此它们隐藏在界面后面。什么签名最适合add_painter界面中的功能?我应该直接使用voidadd_painter(w

c++ - 使用 GTest 和 GMock : shared vs. 静态库进行测试

我认为这个问题可能违反了网站的一些问答标准,因为我可能收到的答案可能被视为意见驱动。尽管如此,它还是...假设我们正在处理一个C++项目,使用CMake来驱动构建/测试/打包过程,并使用GTest和GMock进行测试。进一步假设我们项目的结构如下所示:cool_project||--source||||--module_foo||||||--(bunchofsourcefiles)||||--module_bar||||--(yetmoresourcefiles)||--tests||--module_foo||||--(testsformodule_foo)||--module_ba