Jump to content
  • Advertisement
Sign in to follow this  
hotpixel

overloading the = operator

This topic is 3472 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 am probably being a complete noob and not understanding the operator overload function so could someone please tell me why this isn't working:
Quote:
WCHAR* operator=( char n[] ) {WCHAR *wszName;WCHAR wszBuf[MAX_PATH];wszName = wszBuf;MultiByteToWideChar( CP_ACP, 0, n, -1, wszName, MAX_PATH );return wszName;}
basically what I am trying to do is hide all the windows code so that in my high level classes so you can submit "some text value" to a low level method then I can easily do something like WCHAR* wszName = passedName; instead of having to write a method that I am constantly calling or having to enter windows specific syntax in my high level classes, eg L"some text value". I may just be putting my operator overload in the wrong place. At the moment its just in my class definition where I'll be wanting to convert it. I maybe completely misunderstanding the idea of abstracting my code so can some please help me out, Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The assignment operator can only be overloaded as a class member. Also, don't return pointers to local buffers: they are invalid. Unless converting strings this way is a core process of your application that required insanely tight performance, you will gain a few weeks' work by using the standard library for things like this. In fact, since you mention high level classes, you should be using the standard library anyway.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!