|
From: Murrgon on 3 Jun 2008 14:03 class TTexture; typedef TSmartPtr<TTexture> TTexturePtr; typedef TArray<TTexturePtr> TTexturePtrArray; TTexturePtrArray apTextures; I am having the most bizarre compiler error. Code that has been working for years all of a sudden, in one particular case, throws a compiler error: for (UINT i = 0; apTextures.Size() > i; ++i) { if (NULL != apTextures[i]) { // Do something } } error C2593: 'operator !=' is ambiguous As this is dealing with templates, the compiler comes along and tells you what types it thinks might fit. The weird part is, none of the suggested types have anything to do with a TTexture. What? I don't know how the compiler resolves the types, but something is messed up. I can get around the problem by either typecasting NULL to a TTexture* or reversing the order of the comparison (i.e. apTextures[i] != NULL), but I shouldn't need to. This code is used in countless other instances and all of them compile just fine. Murrgon
From: Bo Persson on 3 Jun 2008 15:04 Murrgon wrote: > class TTexture; > typedef TSmartPtr<TTexture> TTexturePtr; > typedef TArray<TTexturePtr> TTexturePtrArray; > > TTexturePtrArray apTextures; > > I am having the most bizarre compiler error. Code that has been > working for years all of a sudden, in one particular case, throws a > compiler error: > > for (UINT i = 0; apTextures.Size() > i; ++i) > { > if (NULL != apTextures[i]) > { > // Do something > } > } > > error C2593: 'operator !=' is ambiguous > > As this is dealing with templates, the compiler comes along and > tells you what types it thinks might fit. The weird part is, none > of the suggested types have anything to do with a TTexture. What? I > don't know how the compiler resolves the types, but something is > messed up. Do any of the suggested types have an operator!=()? Recently added? Bo Persson
From: Murrgon on 3 Jun 2008 16:17 Bo Persson wrote: > Do any of the suggested types have an operator!=()? > > Recently added? None of the suggested types have operator!=() and none of them were recently added. They were all classes seemingly chosen at random from one of the namespaces I am using. Murrgon
From: Victor Bazarov on 3 Jun 2008 16:54 Murrgon wrote: > Bo Persson wrote: >> Do any of the suggested types have an operator!=()? >> >> Recently added? > > None of the suggested types have operator!=() and none of them were > recently added. They were all classes seemingly chosen at random > from one of the namespaces I am using. Any of the types have conversion to 'int'? To 'long'? To 'double'? We can play this guessing game very long... This is a case of my favourite C++ FAQ Lite 5.8. Look it up. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
From: Murrgon on 4 Jun 2008 11:11
Victor Bazarov wrote: > Any of the types have conversion to 'int'? To 'long'? To 'double'? We > can play this guessing game very long... 2>f:\workroot2\graphicutils\meshinstance.cpp(285) : error C2593: 'operator !=' is ambiguous 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): could be 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::IXMLParser 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::IMesh 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::IResourceManager::TResourceFactory 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::IResourceManager 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::KKernel 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::TProcess 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::KShell 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::IDisplayConsole 2> ] 2> f:\workroot2\gtlibrary\gtdebug\gtsmartptr.h(184): or 'TBool GTL::TSmartPtr<TYPE>::operator !=(TYPE *,const GTL::TSmartPtr<TYPE> &)' [found using argument-dependent lookup] 2> with 2> [ 2> TYPE=MNS::IComponent 2> ] 2> or 'built-in C++ operator!=(MNS::ITexture *, MNS::ITexture *)' 2> or 'built-in C++ operator!=(const MNS::ITexture *, const MNS::ITexture *)' 2> while trying to match the argument list '(int, MNS::TTexturePtr)' Correction to previous post: the 'built-in C++' operator!=() that were suggested obviously has that operator, but none of the classes suggested has that operator. I'm assuming here that 'MNS::ITexture *' or its const version could be converted to int. But then again, if this were a 64bit platform (which it's not), converting a pointer to an int would cause truncation problems I would think. The thing that bothers me is how the heck can it possibly come up with the suggestions it has? MNS::ITexture* makes sense, but all of the others have nothing to do with what is stored in the array. > This is a case of my favourite C++ FAQ Lite 5.8. Look it up. As much as I would love to post a full compilable sample that demonstrates the problem, as I mentioned in my original post, the code compiles fine in all other cases. We're talking hundreds of cases. To be able to provide the code that fails, I'd need to post five different projects worth of code, which doesn't fall under the "small sample" category. |