From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Sat, 20 May 2006 15:50:59 +0300
Local: Sat, May 20 2006 8:50 am
Subject: <Samples> Member and non-member operators
// ========================================== Alex Vinokur
[
#include <iostream> // ------ }; // ------ class Foo { friend Foo operator+ (const Foo& arg1, const Foo& arg2); friend Foo operator+ (int arg1, const Foo& arg2); friend Foo operator+ (const Foo& arg1, int arg2); private: public : Foo& operator- (const Foo& arg) Foo& operator- (int arg) }; // ------ Foo operator+ (const Foo& arg1, const Foo& arg2) { Foo foo; foo.m_value = arg1.m_value + arg2.m_value; cout << "Non-Member: " << __PRETTY_FUNCTION__ << endl; return foo; } // ------ Foo operator+ (int arg1, const Foo& arg2) { Foo foo; foo.m_value = arg1 + arg2.m_value; cout << "Non-Member: " << __PRETTY_FUNCTION__ << endl; return foo; } // ------ Foo operator+ (const Foo& arg1, int arg2) { Foo foo; foo.m_value = arg1.m_value + arg2; cout << "Non-Member: " << __PRETTY_FUNCTION__ << endl; return foo; } // ------ struct Bar { operator Foo () { cout << "operator: " << __PRETTY_FUNCTION__ << endl;} }; // ------ int main () { Foo f0, f1, f2; f0 = f1 + f2; f0 = f1 - f2; cout << endl; cout << endl; cout << endl; return 0; }
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| |||||||||||||||||