草庐IT

non-local

全部标签

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++ - stod 不能与 boost::locale 一起正常工作

我试图在逗号是小数分隔符的德国语言环境中一起使用boost::locale和std::stod。考虑这个代码:boost::locale::generatorgen;std::localeloc("");//(1)//std::localeloc=gen("");//(2)std::locale::global(loc);std::cout.imbue(loc);std::strings="1,1";//floatstringingermanlocale!doubled1=std::stod(s);std::coutstd::localeloc("")创建正确的语言环境,输出为d1:1

c++ - "Control reaches end on non-void function"with do { 返回结果; } 而(条件);

我有以下功能(简化示例):QByteArrayDecompressBytes(constQByteArray&content){/*functionbody(withotherreturnexpressions)*/do{returncontent;}while(content.size()!=0);}添加最后一行用于测试,替换使用的宏。VisualStudio没有发现此代码有问题,但g++生成了warning:controlreachesendofnon-voidfunction[-Wreturn-type]将最后一行更改为returncontent;删除警告。我的问题:为什么编译器

c++ - 嵌套类声明 : template vs non-template outer class

我有一个C++模板类,里面有一个嵌套类,比如:templateclassOuter_t{public:classInner;Inneri;};templateclassOuter_t::Inner{public:floatx;};intmain(){Outer_to_t;//3oranyarbitraryinto_t.i.x=1.0;return0;}编译没有任何问题。然而,一旦我声明了一个类似的非模板类,就像这样:classOuter_1{public:classInner;Inneri;};classOuter_1::Inner{public:floatx;};intmain(){

c++推导 "non type pointer to function"类模板参数

考虑一个模板类:templateclassProxy{voidrun(){ReturnTyperet=Fn();//...dosomething...}};//andafunctionsintfn1(){return5;}floatfn2(){return5;}这可以通过使用实例化:Proxyp1;但是显式声明返回值类型似乎是不必要的。我想要实现的是:someProxyInstantationp1;someProxyInstantationp2;不幸的是,我对c++没有任何期望,这似乎是该语言的一个隐藏角落(至少对我而言)。如果我可以从指向函数的指针获取它的类型——类似于:std::t

c++ - begin() 如何知道要返回哪种返回类型(const 或 non-const)?

这非常有效:listl;list::const_iteratorit;it=l.begin();list::iteratorit2;it2=l.begin();我不明白list是怎么来的“知道”它必须返回iteratorbegin()版本或const_iteratorbegin()const一个。我正在尝试为我的容器(一个trie)实现迭代器,但我遇到了这个问题。难道C++不应该不按返回类型处理差异化(除非使用奇怪的技巧)?这是一些代码和我得到的编译器错误:我的Trie是一个模板化的trie,可以包含任何类型。我有一个Trie::iter非常量迭代器和一个Trie::const_ite

c++ - 'non-virtual interface' 和 'abstract interface' 有什么区别?

我正在用C++实现设计模式,我希望我的类通过组合来利用接口(interface),这让我研究了实现接口(interface)的不同方法。我想澄清一下这个术语的定义。 最佳答案 非虚拟接口(interface)是一个公共(public)成员函数,它不是虚拟的,但通常希望根据可覆盖的虚拟函数来实现:classInterface{public:intcompute(){returncompute_impl();}private:virtualintcompute_impl()=0;protected:virtual~Interface()

c++ - 包括来自/usr/local/include 的头文件和来自/usr/local/lib 的库

我刚刚在OSX10.9上安装了GLFW。header安装到/usr/local/include,库安装在/usr/local/lib。我想知道我还需要做些什么才能让我的C++程序包含像#include"GLFW/glfw3.h"这样的header,而不是像#这样指定整个路径包括“usr/local/include/GLFW/glfw3.h”。图书馆也是如此,因为到目前为止我什至无法使用-lglfw3链接图书馆。提前致谢。 最佳答案 您可以将-I/usr/local/include作为预处理器标志传递给编译器,将-L/usr/loca

c++ - 来自 Voronoi 的 Delaunay boost : missing triangle with non-integral point coordinates

遵循这两个资源:BoostbasictutorialSOQuestion我用boost写了一个Delaunay三角剖分。如果点坐标是完整的(我生成了几个随机测试并且我没有观察到错误),它工作正常。但是,如果这些点不是整数,我会发现许多不正确的三角剖分缺少边缘或错误的边缘。例如这张图片是用四舍五入的值构建的并且是正确的(见下面的代码)但是这个图像是用原始值构建的并且是不正确的(见下面的代码)这段代码重现了这两个例子(没有显示)。#includeusingboost::polygon::voronoi_builder;usingboost::polygon::voronoi_diagram

c++ - block 范围内的 thread_local

thread_local变量在block范围内有什么用?如果一个可编译的样本有助于说明问题,这里是:#include#includenamespaceMy{voidf(int*constp){++*p;}}intmain(){thread_localintn{42};std::threadt(My::f,&n);t.join();std::cout输出:43在示例中,新线程获得了它自己的n但(据我所知)不能用它做任何有趣的事情,所以何必呢?新线程自己的n有没有用?如果它没有用,那又有什么意义呢?自然地,我假设是一个点。我只是不知道这有什么意义。这就是我问的原因。如果新线程自己的n想要(