草庐IT

send_this_email

全部标签

c++ - gcc 与 clang、msvc 和 icc : Is this function call ambiguous?

我能得到的所有编译器都同意这很好:templateautofoo(Check,T...)->void;templateautofoo(int,T...)->void;intmain(){foo(7,"");}但是,根据gcc,以下代码(带有不能从函数参数推导的前导模板参数)是不明确的:templateautobar(Check,T...)->void;templateautobar(int,T...)->void;intmain(){bar(7,"");//ambiguousaccordingtogccbar(7);//justfine}另一方面,clang、msvc和icc对此非常满

move 操作后 C++ lambda ‘this’ 指针失效

我当前的项目中有以下(简化的)代码:#include#include#include#includeclassTest{public:Test()=default;Test(constTest&other)=delete;Test&operator=(constTest&other)=delete;Test(Test&&other)=default;Test&operator=(Test&&other)=default;voidsetFunction(){lambda=[this](){a=2;};}intcallAndReturn(){lambda();returna;}privat

c++ - 直接调用析构函数后 `new (this) MyClass();`是不是未定义行为?

在thisquestionofmine,@DeadMG说通过this指针重新初始化一个类是未定义的行为。标准中有没有提到它?例子:#includeclassX{int_i;public:X():_i(0){std::cout~X();new(this)X(5);}voidprint_i(){std::coutExampleoutputatIdeone(我知道UB也可以是“看似正确的行为”)。请注意,我没有在类外部调用析构函数,因为不访问生命周期已结束的对象。另请注意,@DeadMG说直接调用析构函数是可以的,只要它对每个构造函数调用一次即可。 最佳答案

c++ - noexcept 规范中是否允许使用 `this`?

我有一些代码要求我使用*this,但我希望它是noexcept友好的:structfoo;//Wouldactuallybesomethingwithconditionalnoexceptvoiddo_something(foo&);structfoo{voidfn()noexcept(noexcept(::do_something(*this))){::do_something(*this);}};然而,gccrejectsthis::7:43:error:invaliduseof'this'attoplevelnoexcept(noexcept(::do_something(*th

c++ - enable_shared_from_this 不适用于 xcode 5

#include#includetemplateclassTest:publicstd::enable_shared_from_this>{public:std::shared_ptr>getMe(){returnshared_from_this();};};intmain(intargc,constchar*argv[]){TestaTest;return0;}当我尝试在Xcode5上编译它时,我得到了Useofundeclaredidentifier'shared_from_this'我测试了它并在VisualStudio2010上运行。 最佳答案

The MySQL server is running with the LOCK_WRITE_GROWTH option so it cannot execute this statement

今天发现mysql报错,记录下问题原因;错误信息:TheMySQLserverisrunningwiththeLOCK_WRITE_GROWTHoptionsoitcannotexecutethisstatement向aliyun写入数据,报错。阿里云的一个保护策略,空间剩余不足时,禁止数据写入;可用navicat执行以下sql查看剩余空间大小;SELECTTABLE_SCHEMA,concat(TRUNCATE(sum(data_length)/1024/1024,2),‘MB’)ASdata_size,concat(TRUNCATE(sum(index_length)/1024/1024,

c++ - -O1/2/3 与 -std=c++1y/11/98 - 如果包含 <cmath> 我收到错误 : '_hypot' was not declared in this scope

我刚刚使用mingw-get-setup更新了MinGW而且我无法构建包含的任何内容header如果我使用大于-O0的东西与-std=c++1y.(我也试过c++11和c++98)我收到这样的错误:g++.exe-pedantic-errors-pedantic-Wextra-Wall-std=c++1y-O3-cZ:\Projects\C++\L6\src\events.cpp-oobj\src\events.oInfileincludedfromz:\lander\mingw\lib\gcc\mingw32\4.8.1\include\c++\cmath:44:0,fromZ:\P

c++ - 条件断点 : This expression has side effects and will not be evaluated

我有一个名为size_tA::m()const的非静态常量方法,如果它返回的值大于1,我想用它来触发断点。这是A类和实例a:classA{public:std::vectormyvec;size_tm()const{returnmyvec.size();}}a;所以我在VisualStudio2013中添加了一个断点,这个条件a.m()>1//aisaninstanceofclassA但是,当我尝试编译它时,我从IDE收到以下消息:Thefollowingbreakpointcannotbeset:AtmyFile.cpp,linexxx,when'a.m()>1'istrueThis

c++ - 是否有对象的 `this` 的类似物,但用于函数?

我已经搜索了引用资料和一般网络,但我找不到它是否存在。有没有办法在C++中获取指向当前函数的指针?它是如此微不足道,它应该存在。在完美的世界中,我想找到一种方法来获取当前函数的std::function,但即使是旧式指针也可以。澄清为什么可能需要它:我正在考虑Lambda函数内部的递归,甚至是函数中的一般递归,在未来的版本中很可能会更改名称。 最佳答案 没有,主要是因为没有必要。在(非匿名函数)函数的上下文中,您始终知道自己的位置——您始终可以使用它的名称来引用它或获取它的地址。与不同对象具有不同地址的对象不同,因此需要this。

c++ - 计数位数 : How does this line work ? n=n&(n-1);

这个问题在这里已经有了答案:n&(n-1)whatdoesthisexpressiondo?[duplicate](4个答案)关闭6年前。我需要一些解释这个特定行是如何工作的。我知道这个函数计算的是1的位数,但是这一行究竟是如何清除最右边的1位的呢?intf(intn){intc;for(c=0;n!=0;++c)n=n&(n-1);returnc;}有没有人可以简单的给我解释一下或者给出一些“证明”?