Jump to content
  • Advertisement
Sign in to follow this  
Axiverse

Overloading woes

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a string class and the following piece of code is giving me trouble (or at least it's making my compiler give me trouble.) I have:

wchar_t& operator [] (unsigned int);
wchar_t operator [] (unsigned int) const;

for accessing characters, but when i do this:
String astring = L"Hello Unicode World";
astring[3] = L'#';
<- this gives me trouble. I get:
Main.cpp(18) : error C2666: 'Axiverse::String::operator`[]'' : 4 overloads have
similar conversions
        ...\String.h(29): could be 'wchar_t Axiverse::String::operator [](unsigned int) const'
        ...\String.h(28): or       'wchar_t &Axiverse::String::operator [](unsigned int)'
        or       'built-in C++ operator[(wchar_t, int)'
        or       'built-in C++ operator[(wchar_t, int)'
        while trying to match the argument list '(Axiverse::String, int)'

how do i get it to just choose one of mine? Essentiall they are the same, only one allows user modification and the other one does not.

Share this post


Link to post
Share on other sites
Advertisement
Do you also have an implicit conversion to wchar_t*? If so, the compiler doesn't know whether it should match 'String::operator[](3)' or '(String::operator wchar_t*())[3]'

EDIT: There are 4 matches because the compiler considers the const versions of these functions as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!