Hi. Could you please guide me in performing operator overloading of Unary operator? Just explain the method with an example. Please add the explanation.
majeissh 0 Newbie Poster
Recommended Answers
Jump to PostYou mean the + operator?
class MyClass { private: int x; public: MyClass() {x = 0;} MyClass operator+(int x) { MyClass n = *this; n.x = n.x + x; return n; } };
All 4 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Fbody 682 Posting Maven Featured Poster
LordNemrod 10 Light Poster
Fbody 682 Posting Maven Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.