简体   繁体   中英

How can I overload the assignment operator in c++

Ive been reading this article: https://www.thc.org/root/phun/unmaintain.html , and Ive been trying to implements steps Misleading names (search for isValid(x) ) and How To Fix Unused Variable Errors (#29 under Miscellaneous Techniques).

I wish to do something more useful, (also according to the article) as doing more stuff on less lines is better.

Unfortunately, I have no idea on how to overload the assignment operator for a basic type. I know I could do something like operator=(&Other o) if I was using a class, but alas, C/C++ doesn't take after Java by having classes for some basic types...

Unfortunately, I have no idea on how to overload the assignment operator for a basic type. I know I could do something like operator=(&Other o) if I was using a class

You cannot overload operators for built-in types in C++. And that's the end of the story.

but alas, C/C++ doesn't take after Java by having classes for some basic types...

...You make it sound like Java's distinction between int and Integer is somehow a good thing :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM