草庐IT

shared_int

全部标签

c++ - 带有标准容器的 std::shared_ptr

我有一个容器shared_ptrs和我将这些对象交给WindowsAPI,稍后我使用原始ptr获得回调。我要找对shared_ptr事后。这可以用shared_ptr干净地完成吗?(不使用shared_from_this())。非常基本的例子:classCFoo{};typedefstd::shared_ptrCFooPtr;typedefstd::setCFooSet;externCFooSetm_gSet;voidSomeWindowsCallBack(CFoo*pRawPtr){m_gSet.erase(pRawPtr);}我知道这可以用intrusive_ptr来完成很容易,但

c++ - 如何重新分配 boost shared_ptr

我有两个Boostshared_ptrshared_ptrA(newX);shared_ptrB(newX);第三个指针最初指向与A相同的X。shared_ptrC=A;更改C使其指向与B相同的X的正确方法是什么?C=B; 最佳答案 EdChm是对的。我做了一个小测试程序来明确它。它使用C++11,但可以轻松转置。#include#includeintmain(){std::shared_ptrA(newint(1));//createsasharedpointerpointingtoanint.Soheunderlyinginti

CMake Error at /usr/share/cmake-3.10/Modules/CMakeFindDependencyMacro.cmake:48 (find_package):

问题:CMakeErrorat/usr/share/cmake-3.10/Modules/CMakeFindDependencyMacro.cmake:48(find_package): Foundpackageconfigurationfile:  /home/wl/anaconda3/lib/cmake/Qt5WebKit/Qt5WebKitConfig.cmake butitsetQt5WebKit_FOUNDtoFALSEsopackage"Qt5WebKit"isconsideredto beNOTFOUND. Reasongivenbypackage: Qt5WebKitcould

c# - 将包含 int 和 int[] 的结构从 C# 编码到 C++

我有一个带有非托管代码的C++DLL和一个C#UI。有一个从C++DLL导入的函数,它以我编写的结构作为参数。将我编写的结构(MyImage)从C#编码到C++后,我可以访问其中的int[]数组的内容,但内容不同。我不知道我在这里遗漏了什么,因为我花了很多时间并尝试了一些技巧来解决这个问题(显然还不够)。C#中的MyImage结构:[StructLayout(LayoutKind.Sequential)]structMyImage{publicintwidth;publicintheight;publicint[]bits;//theserepresentcolorsofimage-4

c++ - size_t 和 __w64、time_t 和 __int64 是如何工作的?

我不是C或C++的老手。我不知道time_t是如何定义和设计的。几个帖子,例如:Whatisultimatelyatime_ttypedefto?Whatissize_tinC?Differencebetweensize_tandstd::size_t但是这些帖子只说明什么是time_t或size_t。它没有明确说明time_t或size_t是如何以及在何处定义和声明的。我正在使用WIN8VS2012ExpressC++。我搜索了库,发现size_t是在crtdefs.h中定义的,而不是cstddef。为什么需要size_t、time_t这样的类型?我们可以让sizeof只返回unsi

c++ - 模板别名 shared_ptr 和 unique_ptr 时是否有任何陷阱或限制?

为了减少输入类似内容的简单原因:std::shared_ptr;std::unique_ptr;每次想使用智能指针的时候,我就想到了使用模板别名:templateusingsptr=std::shared_ptr;templateusinguptr=std::unique_ptr;所以我可以像这样使用它们:sptr;uptr;假设我在自己的命名空间中保护它们,以这种方式使用带有shared/unique_ptr的模板别名是否有任何陷阱或限制?我会不会做一些我可以用直接模板语法做而我不能用别名做的事情?由于其他原因,这是一个坏主意吗? 最佳答案

c++ - 在 C++ 中初始化静态 std::map<int, unique_ptr<int>>

这是一个与此post类似的问题.我认为最有前途的答案与模板化静态初始化有关。这是该答案的类(class):templateclasscreate_map{private:std::mapm_map;public:create_map(constT&key,constU&val){m_map[key]=val;}create_map&operator()(constT&key,constU&val){m_map[key]=val;return*this;}operatorstd::map(){returnm_map;}};用法:std::mapmymap=create_map(1,2)(

c++ - boost::ublas 如何获得 int 矩阵的行列式?

我找到了计算boost::ublas矩阵行列式的函数:templateValTypedet_fast(constublas::matrix&matrix){//createaworkingcopyoftheinputublas::matrixmLu(matrix);ublas::permutation_matrixpivots(matrix.size1());autoisSingular=ublas::lu_factorize(mLu,pivots);if(isSingular)returnstatic_cast(0);ValTypedet=static_cast(1);for(std

c++ - c++ 中的 int(或 long long)溢出如何影响模数?

假设我有两个longlong,a和b,我需要相乘,然后得到一些大k的modk值,这样a、b和k都在longlong的范围内,但不在诠释。为简单起见,a,b因此代码将是:longlonga,b,k;cin>>a>>b>>k;cout但是,因为a和b太大了,如果像上面那样相乘,溢出变成负数,那么modk就是负数,不正确。如何确保modk的值是正确的?编辑:作为奖励,这在Java中是如何工作的?是不是和预想的一样?还是需要BigInteger? 最佳答案 许多编译器提供128位整数类型。例如,使用g++你可以创建一个函数staticinl

c++ - (int&&)5 是整数常量表达式吗?

g++接受代码:charb[static_cast(5)];N3936[expr.const]/3将术语定义为:Anintegralconstantexpressionisanexpressionofintegralorunscopedenumerationtype,implicitlyconvertedtoaprvalue,wheretheconvertedexpressionisacoreconstantexpression.[Note:Suchexpressionsmaybeusedasarraybounds[...]我不确定,因为表达式看起来像是int&&类型但是3.9中整数类