BUG: error C2668: ambiguous call to overloaded function

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 110

BUG: error C2668: ambiguous call to overloaded function

Post by Transporter »

Trying to convert intptr_t to string is not working using VS2010 x64

OgreCompositorChain.cpp(105):

Code: Select all

        String compName("Ogre/Scene/");
    compName += StringConverter::toString((intptr_t)mViewport);
On x86 intptr_t is a 32 bit integer which can be converted by

Code: Select all

static String toString(int val, unsigned short width = 0, char fill = ' ', std::ios::fmtflags flags = std::ios::fmtflags(0) );
or

Code: Select all

static String toString(long val, unsigned short width = 0, char fill = ' ', std::ios::fmtflags flags = std::ios::fmtflags(0) );
On x64 intptr_t is a 64 bit integer! A specific function for 64 bit integer is missing, so VS don't know which target system should be used.
1>..\..\OgreMain\src\OgreCompositorChain.cpp(106): error C2668: 'Ogre::StringConverter::toString' : ambiguous call to overloaded function
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(127): could be 'Ogre::String Ogre::StringConverter::toString(bool,bool)'
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(121): or 'Ogre::String Ogre::StringConverter::toString(long,unsigned short,char,std::ios_base::fmtflags)'
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(105): or 'Ogre::String Ogre::StringConverter::toString(unsigned long,unsigned short,char,std::ios_base::fmtflags)'
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(100): or 'Ogre::String Ogre::StringConverter::toString(size_t,unsigned short,char,std::ios_base::fmtflags)'
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(96): or 'Ogre::String Ogre::StringConverter::toString(unsigned int,unsigned short,char,std::ios_base::fmtflags)'
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(91): or 'Ogre::String Ogre::StringConverter::toString(int,unsigned short,char,std::ios_base::fmtflags)'
1> c:\work\ogre\ogre\ogremain\include\OgreStringConverter.h(73): or 'Ogre::String Ogre::StringConverter::toString(Ogre::Real,unsigned short,unsigned short,char,std::ios_base::fmtflags)'
1> while trying to match the argument list '(intptr_t)'
Bugfix:
ogre-32-64-stringconverter.patch
http://www.ogre3d.org/mantis/view.php?id=554
You do not have the required permissions to view the files attached to this post.
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: BUG: error C2668: ambiguous call to overloaded function

Post by CABAListic »

Good find. The following issue on the patch tracker is also related in that it requires a conversion function for pointers: http://sourceforge.net/tracker/?func=de ... tid=302997

So these should be fixed in one go.
Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 110

Re: BUG: error C2668: ambiguous call to overloaded function

Post by Transporter »

Maybe it is a good idea to rewrite the StringConverter class systematically with all standard types.
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: BUG: error C2668: ambiguous call to overloaded function

Post by CABAListic »

I decided not to add another toString method to StringConverter in the 1.8 branch. Although unlikely, it might hypothetically lead to additional ambiguities in existing client code, which I didn't want to risk in the stable branch. So instead I simply cast the pointer to size_t instead of intptr_t, since for size_t we already have a toString method. And size_t should have the necessary size on all platforms, even though it's not guaranteed by the standard.

For 1.9 we should replace all of the toString methods with a template method, given that they are just wrappers around a stringstream, anyway.
Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 110

Re: BUG: error C2668: ambiguous call to overloaded function

Post by Transporter »

Your quick patch has not been merged to 1.9 branch.