草庐IT

static-variables

全部标签

c++ - 为什么异常不适用于 OSX 上的 gcc7 和 -static-libgcc?

如果我用gcc-7、-static-libstdc++和-static-libgcc编译这个简单的程序;然后在OSX上运行#include#includeintmain()try{throwstd::runtime_error{"abc123"};return0;}catch(conststd::runtime_error&e){std::cout失败,错误代码为134。为什么它不像在linux上使用相同选项编译时那样打印“abc123”? 最佳答案 已在GCC8中修复(-ish);查看对PR86215的更新和相关的PR80556.

c++14 static constexpr auto 与 odr 用法

我有以下C++14代码:templatestructTest{staticconstexprautosomething{T::foo()};};这很好,只要T::foo()也是一个constexpr。现在我知道something是ODR使用的,所以我需要提供命名空间声明。我应该使用什么语法?templateconstexprautoTest::something;不起作用。谢谢! 最佳答案 通过using定义的类型名怎么样?templatestructTest{usingsomeType=decltype(T::foo());sta

c++ - 为什么 Qt 对 void* 使用 reinterpret_cast 而不是 static_cast?

您可以使用static_cast将任何指向T的指针转换为void*或将其转换为void*,为什么Qt使用reinterpret_cast?intSOME_OBJECT::qt_metacall(QMetaObject::Call_c,int_id,void**_a){_id=QMainWindow::qt_metacall(_c,_id,_a);if(_id(_a[1])));break;default:;}_id-=1;}return_id;} 最佳答案 老实说,我也一直没弄明白。void**结构的创建方式相同,只需将int*转换

NX二次开发UF_translate_variable 函数介绍

文章作者:里海来源网站:https://blog.csdn.net/WangPaiFeiXingYuanUF_translate_variableDefinedin:uf.h intUF_translate_variable(constchar*variable,char**translation)overview概述Translatesenvironmentvariablestotheirequivalencestrings.Youmustsupplythecompletenameofthevariableargument.Thepointerpassedbackpointstoanoper

c++ - 定义静态全局数组以避免在函数中定义它

我刚刚开始使用作者声称“高度优化”的代码块。在某些时候他们会这样做:namespacesomename{staticfloatarray[N];}floatSomeclass::some_function(std::vector&input){//usesomename::arrayinsomewayreturnresult;}作者没有将somename::array包含在类中,因为持久性代码存在问题(我们几乎无法控制)。当调用some_function时,该类对数组执行O(N^2)次操作。所以如果我在函数调用中移动array,floatSomeclass::some_function

c++ - 谷歌 V8 : access local variables in C++

有人知道如何在C++的嵌套函数调用中查找局部变量吗?考虑以下示例://e.g.aglobalvariableinthebrowservarglobal="global_value";functionfoo(){varglobal="local_value";myCppFunction("global",global);}foo();我现在的问题是,在myCppFunction的实现中,我如何从“foo”访问函数局部变量“global”(不是值,这将由第二个参数给出)?HandleMyCppFunction(constArguments&args){LocalvarName=args[0

c++ - 了解使用 std::condition_variable 的示例

有一个使用condition_variable的例子来自cppreference.com:#include#include#include#include#include#includeintmain(){std::queueproduced_nums;std::mutexm;std::condition_variablecond_var;booldone=false;boolnotified=false;std::threadproducer([&](){for(inti=0;ilock(m);std::coutlock(m);notified=true;done=true;cond

c++ - BOOST_STATIC_ASSERT_MSG - 缺少错误信息

我在让BOOST_STATIC_ASSERT_MSG发出有意义的错误消息时遇到问题。我把它归结为:#includenamespaceStaticChecks{BOOST_STATIC_ASSERT_MSG(false,"Whereismyerrormessage?");}指定的错误信息无处可见。相反,我得到以下信息:c:\tryit>x86_64-w64-mingw32-g++-O0-g-m64-Wall-IC:\boost_1_50_0-IC:\MinGW-W64\msys\includecompiletimechecks.cpp-c-ocompiletimechecks.cpp.o

c++ - 在方法/函数中使用 `static const std::string` 还是只使用 `const std::string` 更好?

我有一个方法/函数:voidfoo(){staticconststd::stringstrSQLQuery="SELECT...";//ormaybeconststd::stringstrSQLQuery="SELECT...";//someoperationsonstrSQLQuery//i.e.concatenatingwithWHERE,etc.:conststd::stringstrSQL=strSQLQuery+strWHERE;doSthOnDataBase(strSQL);}(SQL只是一个例子)staticconst只会被初始化一次,但会一直保存在内存中直到进程结束。c

c++ - "static functions with block scope are illegal"错误取决于初始化样式?

我有一个类Library,其中包含一个结构Transaction,该结构有一个类型为Patron的成员变量。classPatron{public:Patron(){}};classLibrary{public:structTransaction{Patronp;Transaction(Patronpp):p(pp){}Transaction();};};对于Transaction的默认构造函数,我有一个函数default_transaction()返回对静态对象的const引用,正如Stroustrup在“编程-原则和实践”中所推荐的使用C++”(第324页);推理:避免在构造函数代码