草庐IT

Declaration

全部标签

c++ - 可以将变量重新声明为推断为相同类型的 auto 吗?

这个问题在这里已经有了答案:Doesadeclarationusing"auto"matchanexterndeclarationthatusesaconcretetypespecifier?(3个回答)关闭6年前。标准是否允许以下​​内容?#includeexterninta;autoa=3;intmain(int,char**){std::coutclang接受代码。g++提示声明冲突。 最佳答案 从标准上我不太清楚,但是,有这样写的section7.1.6.4autospecifierAprogramthatusesautoi

c++ - 可以将变量重新声明为推断为相同类型的 auto 吗?

这个问题在这里已经有了答案:Doesadeclarationusing"auto"matchanexterndeclarationthatusesaconcretetypespecifier?(3个回答)关闭6年前。标准是否允许以下​​内容?#includeexterninta;autoa=3;intmain(int,char**){std::coutclang接受代码。g++提示声明冲突。 最佳答案 从标准上我不太清楚,但是,有这样写的section7.1.6.4autospecifierAprogramthatusesautoi

c++ - 尝试通过 using-declaration 定义命名空间成员

考虑以下程序。它的格式是否符合c++标准(需要引用标准的相关部分):namespaceX{externinti;}namespaceN{usingX::i;}intN::i=1;intmain(){}对于不同的编译器,我得到了不同的结果。我正在尝试找出我应该为哪个编译器提交错误报告:Clang:给出以下编译器错误:命名空间“N”中没有名为“i”的成员GCC和VisualC++编译它没有错误。为了比较,以下给出了所有三个编译器的编译器错误:namespaceX{voidf();}namespaceN{usingX::f;}voidN::f(){};intmain(){}

c++ - 尝试通过 using-declaration 定义命名空间成员

考虑以下程序。它的格式是否符合c++标准(需要引用标准的相关部分):namespaceX{externinti;}namespaceN{usingX::i;}intN::i=1;intmain(){}对于不同的编译器,我得到了不同的结果。我正在尝试找出我应该为哪个编译器提交错误报告:Clang:给出以下编译器错误:命名空间“N”中没有名为“i”的成员GCC和VisualC++编译它没有错误。为了比较,以下给出了所有三个编译器的编译器错误:namespaceX{voidf();}namespaceN{usingX::f;}voidN::f(){};intmain(){}

c++ - 模板别名上下文中的模板<>模板<>语法是什么?

(这个问题与模板模板参数无关。)我刚刚发现GCC会编译这样的代码templatestructP{};templatetemplateusingQ=P;在哪里Q是一个双模板名称。但是我不能用这个。当我写Q,我明白了template_template.cpp:10:5:error:‘Q’isnotatemplateQ{};^~~~~~~~template_template.cpp:10:20:error:invaliduseofincompletetype‘Q’Q{};^template_template.cpp:2:8:note:declarationof‘Q’structP{};为什么

c++ - 模板别名上下文中的模板<>模板<>语法是什么?

(这个问题与模板模板参数无关。)我刚刚发现GCC会编译这样的代码templatestructP{};templatetemplateusingQ=P;在哪里Q是一个双模板名称。但是我不能用这个。当我写Q,我明白了template_template.cpp:10:5:error:‘Q’isnotatemplateQ{};^~~~~~~~template_template.cpp:10:20:error:invaliduseofincompletetype‘Q’Q{};^template_template.cpp:2:8:note:declarationof‘Q’structP{};为什么

c++ - 哪个查找规则阻止编译器查找函数?

voidFoo(inti){}structBar{staticvoidFoo(){Foo(1);}};以上代码无法编译。它找不到Foo(int)。为什么?我知道这与具有相同的函数名称有关,但没有进一步了解问题。为什么我需要一个合格的查找? 最佳答案 从3.4.1(强调我的)Inallthecaseslistedin3.4.1,thescopesaresearchedforadeclarationintheorderlistedineachoftherespectivecategories;namelookupendsassoonas

c++ - 哪个查找规则阻止编译器查找函数?

voidFoo(inti){}structBar{staticvoidFoo(){Foo(1);}};以上代码无法编译。它找不到Foo(int)。为什么?我知道这与具有相同的函数名称有关,但没有进一步了解问题。为什么我需要一个合格的查找? 最佳答案 从3.4.1(强调我的)Inallthecaseslistedin3.4.1,thescopesaresearchedforadeclarationintheorderlistedineachoftherespectivecategories;namelookupendsassoonas

c++ - 为什么变量声明和for循环的条件一样好用?

像inti=5这样的声明的返回值/类型是什么?为什么不编译这段代码:#includevoidfoo(void){std::cout虽然这样做#includevoidfoo(void){std::cout 最佳答案 for循环要求condition是表达式或声明:condition-eitheranexpressionwhichiscontextuallyconvertibletobool.Thisexpressionisevaluatedbeforeeachiteration,andifityieldsfalse,theloopis

c++ - 为什么变量声明和for循环的条件一样好用?

像inti=5这样的声明的返回值/类型是什么?为什么不编译这段代码:#includevoidfoo(void){std::cout虽然这样做#includevoidfoo(void){std::cout 最佳答案 for循环要求condition是表达式或声明:condition-eitheranexpressionwhichiscontextuallyconvertibletobool.Thisexpressionisevaluatedbeforeeachiteration,andifityieldsfalse,theloopis