草庐IT

c++ - 我不明白标准中的 3.4/2

我不明白标准中的3.4/2:Aname“lookedupinthecontextofanexpression”islookedupasanunqualifiednameinthescopewheretheexpressionisfound.如果名称是限定的,如下面的N::i怎么办?#includenamespaceN{inti=1;}intmain(){inti=0;std::cout限定名称N::i没有在N::i所在的范围内查找,即它没有在main的范围内查找()和全局范围! 最佳答案 为了扩展@JerryCoffin的评论,合格

不明白为什么这四个符号相同?

阵列声明:intarr[]={34,65,23,75,76,33};四个符号:(考虑i=0)arr[i]和*(arr+i)和*(i+arr)和i[arr]看答案让我们看一下您的数组在记忆中的布局:lowaddresshighaddress||vv+----+----+----+----+----+----+|34|65|23|75|76|33|+----+----+----+----+----+----+^^^^|||...etc|||||arr[2]|||arr[1]|arr[0]第一个元素是arr[0],第二arr[1]很清楚,这就是每个人都学到的。不清楚的是编译器实际上翻译了一个表达式a

c++ - 使用 clang 对 std::atomic 函数的调用不明确

我正在尝试使用clang编译我的代码,我之前使用的是g++。我在编译以下代码时遇到错误:#includetypedefvoid(*my_func)();intmain(intargc,char**argv){std::atomic_func;_func();return0;}错误是:a.cpp:23:3:error:calltoobjectoftype'std::atomic'isambiguous_func();^~~~~/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/atomic:304:7:

c++ - 不明确的类命名空间问题

我...觉得问这个问题真的很傻,但我不确定如何解决这个问题。这是我的代码(Objective-C++)的一小段:#include"eq/eq.h"namespaceeqOther{classWindow:publiceq::Window//我得到的错误是:Useof'Window'isambiguous它说它在X.h中被声明为typedefXIDWindow而在window.h中被声明为classeq::Window是它的父类(superclass)。我声明的类应该在namespaceeqOther是吗?eqOther::Window不同于eq::Window!?我觉得自己太蠢了,但我

通用模板 ostream << 运算符的 C++ 不明确重载

这个问题紧接我之前的问题:Genericoperator我想在哪里实现一个通用的适用于拥有to_str()的任何类的运算符方法。我已经成功地检查了一个类是否实现了to_str()方法与用途std::cout感谢这个answer.但是,我在编写模板时遇到困难ostream运营商制作std::cout有效。以下测试代码:#include#include#includetemplateusingvoid_t=void;templatestructhas_to_string:std::false_type{};templatestructhas_to_string().to_str())>>:

c++ - Visual C++ 编译器为不明确的符号提供了错误的行引用

代码如下:namespacen1{templatevoidn2();templatevoidn2(T);}namespacen2/*line12*/{classc{};}usingnamespacen1;namespacen3{voidfoo(n2::c);}voidn3::foo(n2::c)/*line24*/{}尝试使用最新版本的VisualC++编译它时出现以下错误:1>test.cpp(24):errorC2872:'n2':ambiguoussymbol1>test.cpp(12):note:couldbe'n2'1>test.cpp(24):note:or'n2'第12行

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++ - 目标类不明确的 Dynamic_cast

我刚刚在读Stroustrup的新书。在第22.2.2章中,他讨论了dynamic_cast问题。我自己写的测试代码如下:classStorable{public:inti;virtualvoidr(){};Storable(){i=1;};};classComponent:publicvirtualStorable{public:Component(){i=1;};};classReceiver:publicComponent{public:Receiver(){i=2;};};classTransmitter:publicComponent{public:Transmitter()

c++ - 重载调用不明确

我有以下编译器错误:“重载‘reduceColors(ipl_image_wrapper&,ipl_image_wrapper&,int)’的调用不明确”我有一个IplImage(DrawingDetection.h)的包装类:#include#include#include#include#include#include"Utils.h"classipl_image_wrapper{public:typedefboost::shared_ptripl_image_ptr_t;ipl_image_wrapper(){}ipl_image_wrapper(IplImage*img):_i

c++ - 如何解决由内联命名空间中的标识符冲突引起的不明确引用

考虑以下代码:#includeinlinenamespaceN1{intx=2;}intx=1;intmain(){std::cout这显然让我在std::cout上出错referencetoxisambiguous.::x也不起作用。我明白为什么会这样,但是如何在不重命名或删除变量或namespace的情况下解决这个问题?或者这是唯一的解决方案? 最佳答案 内联命名空间作用域变量具有静态storageduration(内部链接)。所以声明externintx;在显示x之前会为您完成LiveonColiru.这样,在名称查找期间将不