草庐IT

MY_NAMESPACE

全部标签

c++ - 在这种情况下,为什么 g++ 和 clang 会破坏 namespace 抽象?

编译:structstr{};namespacea{voidfoo(strs){}}namespaceb{voidfoo(strs){}voidbar(strs){foo(s);}}intmain(int,char**){return0;}但这不是(将结构定义移到命名空间a内)namespacea{structstr{};voidfoo(strs){}}namespaceb{voidfoo(a::strs){}voidbar(a::strs){foo(s);}}intmain(int,char**){return0;}我得到的错误是bad.cpp:Infunction‘voidb::b

python:`del my_list` vs` del [my_list]

我在Python中创建了一个列表>>>my_list=[1,2,3,4]现在,如果我想删除列表,我想使用del操作员喜欢>>>delmy_list这可以正常工作,并且可能是使用它的一般方法。但是在某个地方,我偶然发现了不寻常的语法>>>del[my_list]这也是同样的事情!现在,我有点困惑DEL的实际运作方式。我可以理解以前的语法del作为内置的陈述,但第二个语法看起来像是我的索引。看答案del服用目标列表名字,请参阅参考文档:del_stmt::="del"target_list就像是作业和for循环,目标列表包括使用[...]和(...)列表和元组语法:del(foo,bar)del[

c++ - 另一个命名空间内的 `using namespace` 范围

这个问题在这里已经有了答案:scopeofusingdeclarationwithinanamespace(5个答案)关闭5年前。我知道我将using指令的范围限制在一个block或一个函数中。然后它将仅适用于该范围。但是如果该block是一个命名空间,它显然适用于同一命名空间的所有block。那是对的吗?至少,以下示例表明:(http://ideone.com/K8dk7E)namespaceN1{structFoo{};}namespaceN2{usingnamespaceN1;Foof;}namespaceN2{Foof2;}intmain(){N2::f2;}我原以为Foof2

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++ : Read a file name from the command line and utilize it in my file

如何从命令行读取文件名并在我的C++代码文件中使用它?例如:./cppfileinputFilenameoutputFilename非常感谢任何帮助! 最佳答案 intmain(intargc,char**argv){stringinFile="";stringoutFile="";if(argc==3){inFile=argv[1];outFile=argv[2];}else{cout 关于C++:Readafilenamefromthecommandlineandutilizeiti

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