草庐IT

variable_which_I_am_using

全部标签

c++ - "-ftrapv"和 "-fwrapv": Which is better for efficiency?

来自GNU的网站:-ftrapvThisoptiongeneratestrapsforsignedoverflowonaddition,subtraction,multiplicationoperations.-fwrapvThisoptioninstructsthecompilertoassumethatsignedarithmeticoverflowofaddition,subtractionandmultiplicationwrapsaroundusingtwos-complementrepresentation.Thisflagenablessomeoptimizationsa

c++ - 由空指针常量 : which behaviour is correct? 初始化

intmain(){constintx=0;int*y=x;//line3int*z=x+x;//line4}引用标准(C++11§4.10/1)Anullpointerconstantisanintegralconstantexpression(5.19)prvalueofintegertypethatevaluatestozerooraprvalueoftypestd::nullptr_t.Anullpointerconstantcanbeconvertedtoapointertype;...有四种可能:第4行没问题,但第3行不行。这是因为x和x+x都是计算结果为0的常量表达式,但

c++ - 通过 using 指令公开私有(private)继承的内部模板

我正在尝试使用using引入public的指令派生类的访问声明一些在基类中声明的内部类模板。代码:templateclassBase{public:templatestructInner;};templateclassDerived:privateBase{public:usingtypenameBase::templateInner;//makeitvisibleInner*ptr;//noneedfortypenamehere,non-qualifiedname};intmain(){}g++和clang++都不编译这段代码,都提示error:expectedunqualified

c++ - 我应该将 "using namespace"放在 C++ 中的命名空间内部还是外部

我的导师在代码审查中这样修改了我的代码:usingnamespaceA;//definedinotherfilesnamespaceB{//dosomething}而不是像这样:namespaceB{usingnamespaceA;//dosomething}将using命名空间放在命名空间之外是否有任何技术原因? 最佳答案 在头文件中,您不应该在全局范围内使用usingnamespaceN;指令。它将在所有客户端代码上强制使用来自N的大量标识符。但是将它放在命名空间X中也可以。请记住,执行usingnamespaceX;的客户端代

c++ - "Use of undefined type"带有 unique_ptr 以转发声明的类和默认移动构造函数/赋值

在下面的代码中,是避免编译错误并在A.cpp中手动包含B.h实现移动构造函数/赋值的唯一方法吗?//A.h#includeclassB;//implementationsomewhereinB.h/B.cppclassA{public:A()=default;~A()=default;A(constA&)=delete;A&operator=(constA&)=delete;A(A&&)=default;A&operator=(A&&)=default;private:std::unique_ptrm_b;};VisualStudio2015给出“错误C2027:使用未定义类型”,因为

c++ - QSocketNotifier : Can only be used with threads started with QThread error

我正在尝试使用QLocalServer作为ipc解决方案。qt的版本是4.6这是我的main.cpp:intmain(intargc,constchar*argv[]){QServertest();while(true){}}这是我的QServer类:classQServer:publicQObject{Q_OBJECTpublic:QServer();virtual~QServer();private:QLocalServer*m_server;QLocalSocket*m_connection;privateslots:voidsocket_new_connection();};Q

c++ - C++ 中的 "using"关键字

我正在学习C++。我的教授使用了一些类似的代码usingfilePath=std::string;usingsetOfPaths=std::set;usingiterOfSet=setOfPaths::iterator;usinglistOfIter=std::list;usingiterList=listOfIter::iterator;usingfileName=std::string;usingmapOfFileName=std::map;usingiterOfMap=mapOfFileName::iterator;setOfPaths_setOfPaths;mapOfFileN

c++ - 为什么不重新锁定互斥锁的 condition_variable 没有等待函数

考虑以下示例。std::mutexmtx;std::condition_variablecv;voidf(){{std::unique_locklock(mtx);cv.wait(lock);//1}std::coutg()“知道”f()正在等待我想讨论的场景。根据cppreference.com不需要g()在调用之前锁定互斥锁notify_one.现在在标记为“1”的行中cv将释放互斥锁并在发送通知后重新锁定它。lock的析构函数之后立即再次释放它。这似乎是多余的,特别是因为锁定是昂贵的。(我知道在某些情况下需要锁定互斥锁。但这里不是这种情况。)为什么condition_variab

c# - 从 C# : should I pass StringBuilder or use unsafe code? 调用非托管函数

我有一个C#程序需要将char缓冲区传递给非托管函数。我发现了两种似乎工作可靠的方法,但我不确定应该选择哪一种。这是非托管函数的签名。extern"C"__declspec(dllexport)intgetNextResponse(char*buffer);第一个选项是将缓冲区定义为StringBuilder,如下所示。//atclasslevel...[DllImport("mydll.dll")]staticexternintgetNextResponse(StringBuilderbuffer);//inmainmethodbody...StringBuildersb=newSt

c++ - 编写 Makefile.am 来调用 googletest 单元测试

我正在尝试将我的第一个单元测试添加到现有的开源项目中。具体来说,我添加了一个名为audio_manager的新类:src/audio/audio_manager.hsrc/audio/audio_manager.cc我创建了一个反射(reflect)实现文件结构的src/test目录结构,并写下了我的googletest单元测试:src/test/audio/audio_manager.cc现在,我正在尝试设置我的Makefile.am来编译和运行单元测试:src/test/audio/Makefile.am我从以下位置复制了Makefile.am:src/audio/Makefile