Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
<Samples> Member and non-member operators
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex Vinokur  
View profile  
 More options May 20 2006, 8:50 am
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

// ==========================================
// * Samples
// * Member and non-member operators
// * Usage Sample Code
// ------------------------------------------
// * Language : C++
// * Content  : Program files, Log files
// * Version  : MOP-1.0
// ------------------------------------------
// * Attachments
//   - mem-nomem-operators-1-0.cpp
//   - mem-nomem-operators-1-0.log
// ==========================================

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ mem-nomem-operators-1-0.cpp 2K ]
// ==========================================
// * Samples
// * Member and non-member operators
// * Usage Sample Code
// ------------------------------------------
// * Language : C++
// * Content  : Program files, Log files
// * Version  : MOP-1.0
// ------------------------------------------
// * Attachments
//   - mem-nomem-operators-1-0.cpp
//   - mem-nomem-operators-1-0.log
// ==========================================

#include <iostream>
using namespace std;

// ------
struct Blah
{

};

// ------
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:
  int     m_value;

public :
  Foo () {}
  Foo (const Blah&)
  {
    cout << "Constructor: " << __PRETTY_FUNCTION__ << endl;
  }

  Foo& operator- (const Foo& arg)
  {
    m_value -= arg.m_value;
    cout << "Member:      " << __PRETTY_FUNCTION__ << endl;
    return (*this);
  }

  Foo& operator- (int arg)
  {
    m_value -= arg;
    cout << "Member:      " << __PRETTY_FUNCTION__ << endl;
    return (*this);
  }

};

// ------
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;
int i1 = 127;
  f0 = f1 + i1;
  f0 = i1 + f1;
  f0 = f1 - i1;
  // f0 = i1 - f1;      // no match for 'operator-' in 'i1 - f1'

  cout << endl;
Blah b1;
  f0 = f1 + b1;
  f0 = b1 + f1;
  f0 = f1 - b1;
  // f0 = b1 - f1;      // no match for 'operator-' in 'b1 - f1'

  cout << endl;
Foo foo;
Bar bar;
  f0 = foo + bar;
  f0 = foo - bar;
  f0 = bar + foo;
  // f0 = bar - foo;    // no match for 'operator-' in 'bar - foo'

  return 0;

  mem-nomem-operators-1-0.log
< 1K Download

    Reply to author    Forward  
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.
Alex Vinokur  
View profile  
 More options May 20 2006, 9:11 am
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Sat, 20 May 2006 16:11:49 +0300
Local: Sat, May 20 2006 9:11 am
Subject: <Samples> Member and non-member operators

// ==========================================
// * Samples
// * Member and non-member operators
// * Usage Sample Code
// ------------------------------------------
// * Language : C++
// * Compiler: GNU g++ 3.4.4
// * Content  : Program files, Log files
// * Version  : MOP-1.1
// ------------------------------------------
// * Attachments
//   - mem-nomem-operators-1-1.cpp
//   - mem-nomem-operators-1-1.log
// ==========================================

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ mem-nomem-operators-1-1.cpp 2K ]
// ==========================================
// * Samples
// * Member and non-member operators
// * Usage Sample Code
// ------------------------------------------
// * Language : C++
// * Compiler: GNU g++ 3.4.4
// * Content  : Program files, Log files
// * Version  : MOP-1.1
// ------------------------------------------
// * Attachments
//   - mem-nomem-operators-1-1.cpp
//   - mem-nomem-operators-1-1.log
// ==========================================

#include <iostream>
using namespace std;

// ------
struct Blah1 {};
struct Blah2 {};

// ------
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:
  int     m_value;

public :
  Foo () {}
  Foo (const Blah1&)
  {
    cout << "Constructor: " << __PRETTY_FUNCTION__ << endl;
  }

  explicit Foo (const Blah2&)
  {
    cout << "Constructor: " << __PRETTY_FUNCTION__ << endl;
  }

  Foo& operator- (const Foo& arg)
  {
    m_value -= arg.m_value;
    cout << "Member:      " << __PRETTY_FUNCTION__ << endl;
    return (*this);
  }

  Foo& operator- (int arg)
  {
    m_value -= arg;
    cout << "Member:      " << __PRETTY_FUNCTION__ << endl;
    return (*this);
  }

};

// ------
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;
int i1 = 127;
  f0 = f1 + i1;
  f0 = i1 + f1;
  f0 = f1 - i1;
  // f0 = i1 - f1;      // no match for 'operator-' in 'i1 - f1'

  cout << endl;
Blah1 b1;
  f0 = f1 + b1;
  f0 = b1 + f1;
  f0 = f1 - b1;
  // f0 = b1 - f1;      // no match for 'operator-' in 'b1 - f1'

  cout << endl;
Blah2 b2;
  // f0 = f1 + b2;      // no match for 'operator+' in 'f1 + b2'
  // f0 = b2 + f1;      // no match for 'operator+' in 'b2 + f1'
  // f0 = f1 - b2;      // no match for 'operator+' in 'b2 + f1'
  // f0 = b1 - f1;      // no match for 'operator-' in 'b1 - f1'

  cout << endl;
Foo foo;
Bar bar;
  f0 = foo + bar;
  f0 = foo - bar;
  f0 = bar + foo;
  // f0 = bar - foo;    // no match for 'operator-' in 'bar - foo'

  return 0;

  mem-nomem-operators-1-1.log
< 1K Download

    Reply to author    Forward  
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.
Alex Vinokur  
View profile  
 More options Jun 10 2006, 1:39 pm
From: Alex Vinokur <ale...@users.sourceforge.net>
Date: Sat, 10 Jun 2006 20:39:14 +0300
Local: Sat, Jun 10 2006 1:39 pm
Subject: <Samples> Member and non-member operators

// ==========================================
// * Samples
// * Member and non-member operators
// * Usage Sample Code
// ------------------------------------------
// * Language : C++
// * Compiler: GNU g++ 4.0.1
// * Content  : Program files, Log files
// * Version  : MOP-1.2
// ------------------------------------------
// * Attachments
//   - mem-nomem-operators-1-2.cpp
//   - mem-nomem-operators-1-2.log
// ==========================================

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn

[ mem-nomem-operators-1-2.cpp 2K ]
// ==========================================
// * Samples
// * Member and non-member operators
// * Usage Sample Code
// ------------------------------------------
// * Language : C++
// * Compiler: GNU g++ 4.0.1
// * Content  : Program files, Log files
// * Version  : MOP-1.2
// ------------------------------------------
// * Attachments
//   - mem-nomem-operators-1-2.cpp
//   - mem-nomem-operators-1-2.log
// ==========================================

#include <iostream>
using namespace std;

// ------
struct Blah1 {};
struct Blah2 {};

// ------
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:
  int     m_value;

public :
  Foo () {}
  Foo (const Blah1&)
  {
    cout << "Constructor: " << __PRETTY_FUNCTION__ << endl;
  }

  explicit Foo (const Blah2&)
  {
    cout << "Constructor: " << __PRETTY_FUNCTION__ << endl;
  }

  Foo operator- (const Foo& arg)
  {
    Foo foo;
    foo.m_value = m_value + arg.m_value;
    cout << "Member:      " << __PRETTY_FUNCTION__ << endl;
    return foo;
  }

  Foo operator- (int arg)
  {
    Foo foo;
    foo.m_value = m_value - arg;
    cout << "Member:      " << __PRETTY_FUNCTION__ << endl;
    return foo;
  }

};

// ------
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;
int i1 = 127;
  f0 = f1 + i1;
  f0 = i1 + f1;
  f0 = f1 - i1;
  // f0 = i1 - f1;      // no match for 'operator-' in 'i1 - f1'

  cout << endl;
Blah1 b1;
  f0 = f1 + b1;
  f0 = b1 + f1;
  f0 = f1 - b1;
  // f0 = b1 - f1;      // no match for 'operator-' in 'b1 - f1'

  cout << endl;
Blah2 b2;
  // f0 = f1 + b2;      // no match for 'operator+' in 'f1 + b2'
  // f0 = b2 + f1;      // no match for 'operator+' in 'b2 + f1'
  // f0 = f1 - b2;      // no match for 'operator+' in 'b2 + f1'
  // f0 = b1 - f1;      // no match for 'operator-' in 'b1 - f1'

  cout << endl;
Foo foo;
Bar bar;
  f0 = foo + bar;
  f0 = foo - bar;
  f0 = bar + foo;
  // f0 = bar - foo;    // no match for 'operator-' in 'bar - foo'

  return 0;

  mem-nomem-operators-1-2.log
< 1K Download

    Reply to author    Forward  
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.
End of messages
« Back to Discussions Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google