草庐IT

example_namespace

全部标签

c++ - 在 namespace 内的 lambda 中使用时找不到运算符重载

以下不编译(使用Clang5.0.0/gcc7.3,std:C++11):Clang中的错误信息:错误:二进制表达式的无效操作数(std::vector>和std::vector>)#include#includenamespacens{usingMyType=std::vector;}//namespacensusingns::MyType;MyType&operator+=(MyType&lhs,constMyType&rhs){for(inti=0;i;Funcoperator+(constFunc&lhs,constFunc&rhs){return[lhs,rhs](){aut

c++ - namespace 别名是否会更改链接?

根据我的理解,.cpp文件中的全局变量得到外部链接。假设有两个源文件,a.cpp和b.cpp://a.cppnamespacea_ns{intfoo;}//b.cppnamespaceb_ns{intfoo;}现在假设两者都在namespacens=a_ns;和namespacens=b_ns;之后。如果a.cpp和b.cpp都使用相同的命名空间ns,这会触发任何未定义的行为吗(我认为)对于foo? 最佳答案 没有。您建议的别名不会改变变量具有限定名称a_ns::foo和b_ns::foo的事实,它们是不同的。

c++ - 如何使用外部链接在 namespace 范围内定义常量 double?

我正在尝试创建一个带有外部链接的命名空间范围常量//insomeincludefile:namespacefoo{constexprdoublebar(){return1.23456;}//internallinkageconstexprdoublebaz=1.23456;//internallinkageconstdoublebing=1.23456;//internallinkage}这可能吗? 最佳答案 是,也不是;你可以使用extern:[C++11:3.5/3]:Anamehavingnamespacescope(3.3.

c++ - 将类放入 namespace

我看到Qt在Ui界面中放置了一个类,如下所示:namespaceUi{classMainWindow;}classMainWindow:publicQMainWindow{...这种方法是否等同于将整个类封闭在命名空间中?它看起来确实更干净。 最佳答案 不,在您的示例中,Ui::MainWindow是与全局命名空间中定义的MainWindow类不同的类。看:namespaceUi{classMainWindow;}classMainWindow{};intmain(){Ui::MainWindowmw;//failsduetoinc

c++ - '简历' : a namespace with this name does not exist while building (VS 2015, OpenCV 3.2)

在VS2015中构建一个简单的OpenCV应用程序时出现错误'cv':anamespacewiththisnamedoesnotexistwhilebuilding虽然我相信我已经完成了为VS配置OpenCV所需的所有步骤(使用本文作为引用http://opencv-srf.blogspot.com/2013/05/installing-configuring-opencv-with-vs.html)类(class)的开始很简单#include"opencv2/imgcodecs.hpp"#include"opencv2/highgui.hpp"#include"opencv2/sti

c++ - caffe 安装 : gcc error namespace "std" has no member "isnan"

我正在尝试安装(py)caffe在ubuntu17.10上然而,当我执行makeall时,出现以下错误:./include/caffe/common.hpp(84):error:namespace"std"hasnomember"isnan"./include/caffe/common.hpp(85):error:namespace"std"hasnomember"isinf"2errorsdetectedinthecompilationof"/tmp/tmpxft_00004921_00000000-19_nesterov_solver.compute_61.cpp1.ii".Mak

c++ - 什么是 `using namespace std;` ,为什么我需要它来使用最新的 C++ 编译器编译程序?

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预期结果。另请参阅:StackOverflowquestionchecklist关闭9年前。Improvethisquestion什么是usingnamespacestd;在最近的C++中?在TurboC++等旧编译器中,这似乎不受支持,因为它会导致编译器错误。在最近的C++编译器中,这是编译和运行程序的唯一方法。

c++ - 写 "::namespace::identifier"和 "namespace::identifier"有什么区别?

我在代码中看到了这两种方法。你能解释一下这两者有什么区别吗?正如我认为它与C++完成命名空间查找的方式有关,您能否也提供一些相关信息,或者提供一个好的文档的链接?谢谢。 最佳答案 示例:#includenamespacex{constinti=1;}namespacey{namespacex{constinti=2;}voidfunc(){std::printf("x::i=%d\n",x::i);std::printf("::x::i=%d\n",::x::i);}}intmain(){y::func();return0;}输出:

c++ - 将 namespace 添加到具有 C header 的 C++ 实现

我们有一个包含C和C++代码的大型项目。对于每个C++实现,除了C++header之外,我们通常还提供一个Cheader以允许功能也可用于.c文件。所以,我们的大部分文件看起来像这样:foo.hpp:classC{intfoo();};foo.h:#ifdef__cplusplusextern"C"{typedefstructCC;//forwarddeclarations#elseclassC;#endifintfoo(C*);//simplyexposesamemberfunctionC*utility_function(C*);//somefunctionality*not*in

c++ - 带有模板函数和 'using namespace' 的 VS2008(+?) 编译器错误

我发现某些代码(如下)的这种奇怪情况无法在VisualStudio2008下编译,并在第12行产生“错误C2872:‘歧义’:模糊符号”。删除最后一行的usingnamespaceRequiredNamespace修复了错误,但我希望将usingnamespace放在文件末尾应该没有效果。它还依赖于作为模板函数的AnotherFunction,所以我希望编译器在错误的范围内生成模板函数,或者在这样做之前没有重置正在使用的命名空间列表。相同的代码在GCC下编译。两个编译器似乎都在usingnamespaceNamespace定义之后为TemplatedFunction生成代码,至少据我所