草庐IT

c++ - 由于 ADL,对模板函数的调用不明确

我和我的同事都被这个问题困扰过几次。编译时#include#include#includetemplatetypenameboost::range_iterator::typefind(Rng&rng,Tconst&t){returnstd::find(boost::begin(rng),boost::end(rng),t);}structSTest{booloperator==(STestconst&test)const{returntrue;}};structSTest2:boost::equality_comparable{booloperator==(STest2const&t

c++ - 使用 using 指令进行不明确的名称查找

不允许将同名的命名空间和类放在一个声明区域中,即namespaceA{}classA{};isill-formed(参见§3.3.1/4)。但是,可以通过using指令引入其中任何一个的名称:namespaceN{namespaceA{inti;}}structA{staticinti;};usingnamespaceN;inti=A::i;//Theglobalstruct,ornamespaceN::A?这段代码格式错误吗?VC++thinksso,以及Clang:main.cpp:7:9:error:referenceto'A'isambiguousinti=A::i;^main

c++ - 为什么我的 T& 和 T&& 复制构造函数不明确?

#includeusingnamespacestd;classMyclass{private:inti;public:templateMyclass(U&lvalue):i(lvalue){coutMyclass(U&&rvalue):i(rvalue){cout错误信息:rightvalue.cpp:Infunction‘intmain(int,char**)’:rightvalue.cpp:15:12:error:callofoverloaded‘Myclass(Myclass&)’isambiguousrightvalue.cpp:15:12:note:candidatesare

c++ - 具有多重继承的 operator() 定义不明确

我用GCC(4.2.1Applebuild5664)编译这段代码#includeusingstd::size_t;templatestructindex{};structa{voidoperator()(size_tconst&){}};structb{templatevoidoperator()(indexconst&){}};structc:publica,publicb{};intmain(intargc,charconst*argv[]){cvc;vc(1);return0;}并给我以下错误:main.cpp:Infunction‘intmain(int,constchar**

c++ - 对基类模板成员函数的访问不明确

在VisualStudio2008中,编译器无法解析下面_tmain中对SetCustomer的调用并使其明确:templatestructProducer{voidSetConsumer(TConsumer*consumer){consumer_=consumer;}TConsumer*consumer_;};structAppleConsumer{};structMeatConsumer{};structShillyShallyProducer:publicProducer,publicProducer{};int_tmain(intargc,_TCHAR*argv[]){Shil

c++ - 不明确的 C++ 编译器错误

以下代码无法编译。该错误似乎是对合并例程的某种模棱两可的调用。我的理解是,STL在std命名空间中有一个合并例程,但据我所知,下面代码中的名称merge应该是唯一的。如果我将merge重命名为xmerge,一切正常。可能是什么问题?名称冲突从何而来?http://codepad.org/uAKciGy5#include#include#includetemplatevoidmerge(constInputIterator1begin1,constInputIterator1end1,constInputIterator2begin2,constInputIterator2end2,Ou

c++ - 我试图在 C++03 中嵌套 boost 的 "map_list_of",但显然构造不明确?

考虑一下:#include#include#include#includeusingboost::assign::map_list_of;conststd::map>test=map_list_of(100,map_list_of(1,'a')(2,'b'))(101,map_list_of(1,'c')(2,'d'));intmain(){std::coutsecond.find(2)->second我希望结果是一个程序,在执行时输出d.相反,Igetthis:$clang++-std=c++03-O2-Wall-pedantic-pthreadmain.cppInfileinclu

c++ - 不明确的 string::operator= 调用隐式转换为 int 和 string 的类型

给定以下程序:#include#includeusingnamespacestd;structGenericType{operatorstring(){return"HelloWorld";}operatorint(){return111;}operatordouble(){return123.4;}};intmain(){inti=GenericType();strings=GenericType();doubled=GenericType();cout它在VisualStudio11上编译,但不是clang或gcc。它有问题,因为它想从GenericType隐式转换为int为cha

c++ - 模板参数不明确 : could not deduce template argument

我正在做一些看起来像这样的包装器:#includetemplatevoidApply(void(T::*cb)(Value),T*obj,Valuev){(obj->*cb)(v);}classFoo{public:voidMyFunc(constint&i){std::cout我收到这个错误:应用:未找到匹配的重载函数。voidApply(void(__thiscallT::*)(Value),T*,Value):模板参数Value不明确,可能是int或constint&。voidApply(void(__thiscallT::*)(Value),T*,Value):无法从const

c++ - 不明确的符号错误?

intii,maxnum;for(ii=1;iimax){//thepartwhereIgetC2872AmbiguousSymbolerrormax=count[ii];//thepartwhereIgetC2872AmbiguousSymbolerrormaxnum=ii;}}我从来没有遇到过这个错误,这真令人沮丧。 最佳答案 您的变量max与std::max()冲突。尝试使用不同的名称,它应该可以修复该错误。 关于c++-不明确的符号错误?,我们在StackOverflow上找到一