草庐IT

static-variables

全部标签

c++ - 错误 : cannot declare variable ‘bg’ to be of abstract type ‘cv::BackgroundSubtractorMOG2’ in OpenCV 3

我最近在我的ubuntu14.10系统中安装了OpenCv并且我正在运行一个程序并且正在运行cv::BackgroundSubtractorMOG2我遇到了一个错误。错误是cannotdeclarevariable‘bg’tobeofabstracttype‘cv::BackgroundSubtractorMOG2’为什么我会遇到这个错误我的代码示例intmain(intargc,char*argv[]){Matframe;Matback;Matfront;vector>hand_middle;VideoCapturecap(0);BackgroundSubtractorMOG2bg;

c++ - 将函数内的大变量声明为 `static` 在性能上有什么不同吗?

不确定之前是否有人问过这个问题。在回答thisverysimplequestion时,我问自己以下内容。考虑一下:voidfoo(){inti{};constReallyAnyType[]data={item1,item2,item3,/*manyitemsthatmaybepotentiallyheavytorecreate,e.g.ofclasstype*/};/*functioncodehere...*/}现在理论上,每次控制达到功能时都会重新创建局部变量,对吗?IE。看看上面的inti-它肯定会在堆栈上重新创建。上面的数组呢?编译器能否聪明到优化它的创建只发生一次,还是我在这里

c++ - 如何 static_assert 给定的函数调用表达式是否可以编译?

有没有一种方法可以检查函数调用表达式是否会在编译时进行编译并对其进行static_assert?还是我应该通过system()调用编译器并检查退出代码?#includetemplatevoidf(Args&&...args,bool);templatevoidg(Args&&...args);intmain(){g(1,2.0,"hello",false);//compilesf(1,2.0,"hello",false);//doesn'tcompile//HowdoIdothis?//static_assert(!does_this_compile(f(1,2.0,"hello",f

c++ - static_cast 和 dynamic_cast 在特定场景中的不同行为

在下面的场景中,我没有弄清楚static_cast和dynamic_cast之间的真正区别:**///withstatic_cast///**classFoo{};classBar:publicFoo{public:voidfunc(){return;}};intmain(intargc,char**argv){Foo*f=newFoo;Bar*b=static_cast(f);b->func();return0;}Output:SuccessfullyBuildandCompiled!**///withdynamic_cast///**classFoo{};classBar:publ

c++ - 不持有锁的本地静态初始化避免了 C++11 中可能出现的死锁?

论文http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm提出了一种算法,该算法在局部静态变量的初始化期间不需要持有锁,但仍会导致通过变量定义的并发控制流等待初始化完成。论文说这样做的好处是避免了可能出现的死锁Thecoreproblemwithfunction-localstatic-durationobjectinitializationisthatthecontainingfunctionmaybeinvokedconcurrently,andthusthedefinitionmayexecuteconc

c++ - sqlite3_bind_text SQLITE_STATIC vs SQLITE_TRANSIENT for c++ string

我有一个返回c++std::string的方法,然后在将其传递到sqlite3_bind_text之前将其转换为c_str()。我的问题是,这应该使用SQLITE_STATIC还是SQLITE_TRANSIENT?sqlite3_bind_text(insertStatement,0,suspect->GetIpString().c_str(),-1,SQLITE_STATIC);//Dosomestuffinsamefunctionthensqlite3_stepsqlite3_bind_text的文档说,Thefifthargumenttosqlite3_bind_blob(),s

c++ - "Static counter"类型行为异常

我正在开发一个基于实体的组件系统,我正在尝试为组件类型分配某个索引:staticstd::size_tgetNextTypeId(){staticstd::size_tlastTypeIdBitIdx{0};++lastTypeIdBitIdx;//Thislineproducestheoutputattheendofthequestionstd::cout::bitIdxwillalwaysbedifferent//fromTypeIdStorage::bitIdxtemplatestructTypeIdStorage{staticconststd::size_tbitIdx;};/

c++ - static_casting a constexpr void* 的结果是常量表达式吗?

clang正在拒绝gcc允许的这段代码:intmain(){staticconstexprconstvoid*vp=nullptr;staticconstexprconstchar*cp=static_cast(vp);}具有以下内容:error:constexprvariable'cp'mustbeinitializedbyaconstantexpressionstaticconstexprconstchar*cp=static_cast(vp);阅读完N3797中的最终list后5.9/2我没有看到任何禁止在常量表达式中使用static_cast的内容。我是在看错地方还是误读了什么

c++ - 显式构造函数和 static_cast

structFoo{explicitFoo(inta):m(a){}intpadd1,m,padd2;};voidBar(Foo){}intmain(){Bar(11);//OK,giveserrorautox=static_cast(37);x.m;}static_cast构造Foo对象是否可以,即使它的构造函数被标记为explicit?它适用于MSVC2013和GCChttp://ideone.com/dMS5kB 最佳答案 是的,static_cast将使用explicit构造函数。5.2.9Staticcast[expr.s

C++ 构造函数 : Initialize local variable before initializer list

如何在构造函数中(在堆栈上)存储初始化列表所需的临时状态?例如,实现这个构造函数……//configabstraction.h#includeclassConfigAbstraction{public:ConfigAbstraction(std::istream&input);private:intm_x;intm_y;intm_z;};...使用这样的有状态助手类?//mysillyparserdontworry.h#include//jsoncppclassMySillyParserDontWorry{public:MySillyParserDontWorry(std::istre