草庐IT

static-constructor

全部标签

c++ - 有没有办法 "statically"将共享的 .so(或 .o)库插入可执行文件?

首先,考虑以下情况。下面是一个程序://test.cppextern"C"voidprintf(constchar*,...);intmain(){printf("Hello");}下面是一个库://ext.cpp(theexternallibrary)#includeextern"C"voidprintf(constchar*p,...);voidprintf(constchar*p,...){std::cout现在我可以用两种不同的方式编译上面的程序和库了。第一种方式是编译程序不链接外部库:$g++test.cpp-otest$lddtestlinux-gate.so.1=>(0x

c++ - "static const int"导致链接错误( undefined reference )

使用以下代码时,我对链接器错误感到困惑://static_const.cpp--completecode#includestructElem{staticconstintvalue=0;};intmain(intargc,char*argv[]){std::vectorv(1);std::vector::iteratorit;it=v.begin();returnit->value;}但是,这在链接时会失败——不知何故,它需要一个符号来表示静态const“值”。$g++static_const.cpp/tmp/ccZTyfe7.o:Infunction`main':static_con

c++ - 错误 C2512 : no appropriate default constructor available

我收到这个烦人的错误,我不知道为什么=(!这是问题,我解决了,但构造函数有问题。WriteaprogramthatdefinesaclasscalledCirclethatincludesradius(typedouble)asdatamembers.Provideasetandagetfunctionforthisdatamember.Ensurethatthevalueenteredbytheuserisvalidandcorrect(greaterthanzero).Includefunctionmembers:a.functionmemberthatcomputeandretu

c++ - static_cast 和 Implicit_cast 有什么区别?

什么是implicit_cast?我什么时候应该更喜欢implicit_cast而不是static_cast? 最佳答案 我正在复制我对answerthiscomment的评论在另一个地方。Youcandown-castwithstatic_cast.Notsowithimplicit_cast.static_castbasicallyallowsyoutodoanyimplicitconversion,andinadditionthereverseofanyimplicitconversion(uptosomelimits.you

c++ - 错误 LNK2001 : unresolved external symbol "private: static class

errorLNK2001:unresolvedexternalsymbol"private:staticclassirrklang::ISoundEngine*GameEngine::Sound::_soundDevice"(?_soundDevice@Sound@GameEngine@@0PAVISoundEngine@irrklang@@A)我无法弄清楚为什么我会收到此错误。我相信我正在正确初始化。有人可以帮忙吗?声音.hclassSound{private:staticirrklang::ISoundEngine*_soundDevice;public:Sound();~Soun

c++ - 重载 static_cast 的调用不明确

我有一些这样的代码structB{B(){}B(intv){}};structA{operatorint()const{return1;}operatorB()const{returnB();}};intmain(){Aa;static_cast(a);//Errorherea.operatorB();//ThisisOKreturn0;}会产生这样的编译错误:main.cpp:Infunction‘intmain()’:main.cpp:16:21:error:callofoverloaded‘B(A&)’isambiguousstatic_cast(a);^main.cpp:4:5

c++ - ARM C++ ABI : Constructor/destructor return values

我一直在阅读Clang源代码,并发现了一些关于ARMC++ABI的有趣之处,我似乎无法理解其理由。来自ARMABIdocumentation的在线版本:ThisABIrequiresC1andC2constructorstoreturnthis(insteadofbeingvoidfunctions)sothataC3constructorcantailcalltheC1constructorandtheC1constructorcantailcallC2.(对于非虚拟析构函数也是如此)我不确定C1、C2和C3在这里引用什么...本节旨在修改来自通用(即安腾)ABI的第3.1.5节,但

c++ - static const 对命名空间成员有什么影响

//MyClass.hnamespaceMyNamespace{staticconstdoubleGasConstant=1.987;classMyClass{//constructors,methods,etc.};}我之前在MyClass声明中声明了GasConstant(并且在源文件中有单独的定义,因为C++不支持非整数类型的const初始化)。但是,我需要从其他文件访问它,而且从逻辑上讲,它似乎应该驻留在命名空间级别。我的问题是,staticconst在这种情况下有什么作用?显然const意味着我不能为GasConstant分配新值,但是命名空间中的静态成员是什么意思。这是否类

c++ - 为什么 "constructor-way"允许在 "for-loop"中声明变量,但不允许在 "if-statement"中声明变量?

这个问题在这里已经有了答案:关闭10年前.PossibleDuplicate:Whycan'tvariablesdefinedinaconditionalbeconstructedwitharguments?考虑这个简单的例子:/*1*/intmain(){/*2*/for(inti(7);i;){break;}/*3*/if(inti(7)){}/*4*/}为什么第2行编译得很好,而第3行给出了错误?这对我来说有点奇怪,为什么if语句在这方面比for循环更糟糕?如果这是特定于编译器的-我使用gcc-4.5.1进行了测试:prog.cpp:Infunction'intmain()':p

c++ - void* 与 static_cast 对比 intptr_t 与 reinterpret_cast

我想知道两种不同类型的非常特殊类型的转换表之间是否存在特定的、基于标准的差异。特别是,给定:类型T和变量T*object是:intptr_topaque=reinterpret_cast(object);T*result=reinterpret_cast(opaque);相当于:void*opaque=static_cast(object);T*result=static_cast(opaque);我只关心result,它是否保证是相同的值,相当于任何类型T的原始object?我不在乎中间opaque有什么位模式,因为我相信标准技术上允许它们在每种情况下都不同(尽管没有理智的编译器会产