Skip to main content
GameDev.net gamedev.net
🔒 Locked

overloading the = operator

Started by hotpixel Dec 19, 2008 at 4:11 AM 1 replies 700+ views
Original Post
hotpixel
hotpixel
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.
ToohrVyk
ToohrVyk
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.
hotpixel
hotpixel
okay, that makes sense, thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.