Sign in to follow this  
hotpixel

overloading the = operator

Recommended Posts

hotpixel    156
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
ToohrVyk    1596
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this