草庐IT

long_ptr

全部标签

c++ - 为什么 "error: invalid application of ' sizeof' 为使用 unique_ptr 的不完整类型”通过添加空析构函数来修复?

这个问题在这里已经有了答案:Isstd::unique_ptrrequiredtoknowthefulldefinitionofT?(9个回答)关闭7年前。我在类里面拉皮条STFT.在header中用这个编译就好了:classSTFT;//pimplofftopreventpointnameclashclassWhatever{private:STFT*stft;这在实现中:#include"STFT.h"Whatever::Whatever():stft(newSTFT()){//blahblah}Whatever::~Whatever(){deletestft;//pureevil

c++ - 我应该使用 QScopedPointer 还是 std::unique_ptr?

我正在开始一个新项目,使用Qt5和QMAKE_CXXFLAGS+=-std=c++1y。我不确定我应该更喜欢QScopedPointer还是std::unique_ptr。我读了somewhereQScopedPointer不再那么酷了。QScopedPointer是否有unique_ptr缺少的功能?在替换QScopedPointer时,是否有任何我不想使用的unique_ptr功能?还是相反? 最佳答案 QScopedPointer严格弱于unique_ptr因为它不支持移动语义。它的功能在其他方面非常相似。移动语义非常有用,不

c++ - 传递给方法时,我应该将 shared_ptr 转换为 weak_ptr 吗?

关于这个主题已经有几个问题,但我仍然不确定该怎么做:我们的代码库在很多地方使用shared_ptr。不得不承认,我们在写的时候并没有明确定义所有权。我们有一些方法,比如voiddoSomething(shared_ptrptr){//doSomething()isamemberfunctionofaclass,butusuallywon'tstoretheptrptr->foo();...}在发现第一个(间接的)循环依赖后,我想纠正我们设计中的错误。但我不确定如何。将上面的方法更改为有什么好处吗?voiddoSomething(weak_ptrptr){shared_ptrptrSha

c++ - 持有 2^63 -1 in long long

我在WindowsXP(代码:Block,MinGW)和Ubuntu(11.04,G++)上运行了以下两段代码我无法运行以下代码#includeusingnamespacestd;intmain(){longlonga=9223372036854775807;cout那个数字是2^63-1。但我会收到一条错误消息:C:\DocumentsandSettings\JohnWong\MyDocuments\codeblock\343_hw_1\main.cpp|9|error:integerconstantistoolargefor"long"type|在ubuntu上-它编译了,但返回的

c++ - 为什么 long int 数据类型的左位移 << 不超过 31?

我想在我的程序中使用以下代码,但gcc不允许我将1左移超过31。sizeof(longint)显示8,那是不是意味着我可以左移到63?#includeusingnamespacestd;intmain(){longintx;x=(~0&~(1编译输出如下警告:leftshift`count>=width`oftype[enabledbydefault]`x=(~0&~(1输出为-1。如果我左移31位,我会得到2147483647,正如int所期望的那样。我希望打开除MSB之外的所有位,从而显示数据类型可以容纳的最大值。 最佳答案 尽

c++ - 在一组 shared_ptr 中找到一个值

我有一组shared_ptr并想在其中找到一个值:typedefstd::shared_ptrIntPtr;structCompare{booloperator()(constIntPtr&a,constIntPtr&b){return*as;autox=std::make_shared(3);s.insert(x);boolfound=s.find(std::make_shared(3))!=s.end();它可以工作,但效率不高-每次尝试查找值时都需要新的临时指针。还有其他办法吗?看起来像Searchinginasetofshared_ptr有一些可能有用的想法吗?

c++ - "error: use of deleted function"在 move 构造函数中对 unique_ptr 调用 std::move 时

#includeclassA{public:A(){}A(constA&&rhs){a=std::move(rhs.a);}private:std::unique_ptra;};此代码无法使用g++4.8.4编译并抛出以下错误:error:useofdeletedfunction‘std::unique_ptr&std::unique_ptr::operator=(conststd::unique_ptr&)[with_Tp=int;_Dp=std::default_delete]’a=std::move(rhs.a);^我知道unique_ptr的复制构造函数和复制赋值构造函数已删除

c++ - 如何解决 boost::shared_ptr 和使用 std::shared_ptr 之间的冲突?

如果我在此代码段中从boost::shared_ptr更改为std::shared_ptr,我将收到链接器错误。#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include//usingnamespacestd;//usingnamespaceboost;usingstd::string;usingstd::ostringstre

c++ - 从函数返回的 unique_ptr 的范围是什么?

这能正常工作吗?(见示例)unique_ptrsource(){returnunique_ptr(newA);}voiddoSomething(A&a){//...}voidtest(){doSomething(*source().get());//unsafe?//Whendoesthereturnedunique_ptrgooutofscope?} 最佳答案 从函数返回的unique_ptr没有范围,因为范围只适用于名称。在您的示例中,临时unique_ptr的生命周期以分号结束。(所以是的,它会正常工作。)一般来说,当完整表达

c++ - 如何从 unsigned long long 掩码中获取数字?

我想知道如何反转像this这样的东西.所以有一个mask其中automask=1ULL如何获得20从面具出来? 最佳答案 无循环很多年前,当我为国际象棋引擎编写按位算法时,我发现了一个快速实现,它对您的要求很有用,它是无循环的。此方法将返回第一个1位从右到左(最低有效位)的位置:inlineunsignedintlsb(unsignedlonglongvalue){if(!value)return-1;value&=-value;unsignedintlsb=(unsigned)value|(unsigned)(value>>32)