草庐IT

has_begin_member

全部标签

c++ - SFINAE:如果不带参数调用,则会出现不明确的重载

考虑以下典型的SFINAE测试函数(它检查类型是否具有begin()成员函数)templateconstexprboolhas_begin_member(...){returnfalse;}templateconstexprboolhas_begin_member(decltype(std::declval().begin())*=0){returntrue;}我可以用参数调用它:has_begin_member(0);//yieldsfalse但没有任何参数:has_begin_member();//compilationerror它会导致以下歧义:error:callofoverl

C++ 编译器错误 "cannot be thread-local because it has non-POD type”“

这个声明:___threadAa;生成此错误:cannotbethread-localbecauseithasnon-PODtypeA在哪里classA{public://functiondeclarationprivate://datamembers};我正在尝试使用命令ogsincludes&ogsmk在Linux上进行编译。我们有静态线程,即在我们的应用程序进入之前,我们知道线程的数量,因此目前的工作是通过声明A的数组来完成的,即Aa[Numberofthreads].我该如何解决这个问题? 最佳答案 假设您使用gcc,线程本

c++ - 增量构建 : Eclipse CDT does not notice that source has changed

在EclipseCDT中点击“构建”符号时,应该只构建已更改的源文件。EclipseCDT的一个非常恼人的行为是它经常忽略已进行的“微小”更改,但并不清楚微小的含义。然后输出是13:21:06****IncrementalBuildofconfigurationforproject****makeallmake:Nothingtobedonefor`all'.我测试刚刚所做的更改的唯一方法是清理并完全重建整个项目,这会浪费很多时间。这可能是什么问题,我该如何修复增量构建?编辑:会不会因为一些时钟同步问题而忽略了最近发生的变化? 最佳答案

c++ - 非成员函数 begin()/cbegin() 及其constexpr-ness

C++11引入了没有constexpr-说明符的std::begin()非成员函数,然后C++14更新为constexpr-std::begin()用于数组类型(T(&)[N])并附加constexpr-std::cbegin()用于通用容器类型(constC&).引自http://en.cppreference.com/w/cpp/iterator/begintemplateconstexprT*begin(T(&array)[N]);//(sinceC++14)templateconstexprautocbegin(constC&c)->decltype(std::begin(c)

c++ - 谁放狗出来的? - 当 "Is-A"在类层次结构中遇到 "Has-A"时对象销毁

考虑一下:classFluffyThing{public:FluffyThing(){m_pMyFur=newFur;}virtual~FluffyThing();protected:Fur*m_pMyFur;};classClawedFluffyThing:publicFluffyThing{public:ClawedFluffyThing():FluffyThing(){m_pMyClaws=newClaws;}virtual~ClawedFluffyThing();protected:Claws*m_pMyClaws;};classScaryFluffyThing:publicC

c++ - 警告 : non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]

这个问题在这里已经有了答案:C++ArrayInitializersWarnings(2个答案)关闭8年前。我刚刚在我的机器上安装了最新版本的cygwin和eclipseluna。它工作正常,我能够运行我的项目。但是,当我构建它们时,我收到了我不明白的警告。例如,这是我从“c++Primer”一书的网站上获得的头文件“Sales_item.h”的警告:warning:defaultedanddeletedfunctionsonlyavailablewith-std=c++11or-std=gnu++11[enabledbydefault]Sales_item()=default;^..

c++ - 为非数组重载 std::begin() 和 std::end()

假设我有以下Data类:structData{charfoo[8];charbar;};和以下函数,my_algorithm,它采用一对char*(类似于STL算法):voidmy_algorithm(char*first,char*last);对于Data的foo数据成员,而不是像这样调用my_algorithm():Datadata;my_algorithm(data.foo,data.foo+8);我可以使用std::begin()和std::end()便捷功能模板:my_algorithm(std::begin(data.foo),std::end(data.foo));我想实

c++ - 您可以向 union 成员发送 "pointer to member"吗?

我能找到的所有描述都在类的上下文中谈论“指向成员的指针”。union与结构非常相似,尤其是也有成员。您能否也提供指向这些成员的指针?例如unionx{inta;floatb;};intx::*p=&x::a;我不是在谈论作为一个整体的union体的指针,作为union体成员的指针等。上面示例中的p实际上是一个偏移量,显然大小为0。我需要这个构造来回答thisquestion. 最佳答案 §3.9.2/1:复合类型可以通过以下方式构造:......指向非静态50类成员的指针,它们标识给定类的对象中给定类型的成员,§8.3.3/1:在声

c++ - 使用 -g 选项编译但 "Single stepping until exit from function main, which has no line number information"

我在使用gdb时遇到了一些问题。这是我在一个名为main.cpp的文件中的代码#includevoidmyfunc();intmain(){charmsg[]="HelloWorld!";myfunc();std::cout我使用这个命令来编译这段代码:g++-g-Wallmain.cpp-ofoo接下来,我使用了gdb:$gdbfoo(gdb)startTemporarybreakpoint1at0x80487c3Startingprogram:/home/laptop/workspace/fooTemporarybreakpoint1,0x080487c3inmain()(gdb)

c++ - 错误 : Element <EnableEnhancedInstructionSet> has an invalid value of "NoExtensions"

我想在虚拟机WindowsXP下VS2010下打开别人的C++项目。问题是,我认为该项目似乎是在Windows7下的VS2012下开发的。我已经成功转换了它的相关配置,感谢互联网。但是现在,当我尝试构建这个项目时,出现了以下错误:C:\ProgramFiles\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(147,5):error:Elementhasaninvalidvalueof"NoExtensions".似乎配置更改导致了这个问题。我所做的是将Project->Properties-