overloaded operators

This is a discussion on overloaded operators within the C++ Programming forums, part of the General Programming Boards category; How do you use an overloaded assignment operator to make a type int equal a custom type??? If possible, send ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    6

    overloaded operators

    How do you use an overloaded assignment operator to make a type int equal a custom type??? If possible, send links or examples. Need help desperately!!!!!!!

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Example below. I've overloaded the assignment operator.

    If your class is derived from another, which already has an int assignment operator, just include your new operator.


    Code:
    class MyClass
    {
    private:
    public:
    ...
    MyClass& operator =(int rhs);
    MyClass& operator =(const MyClass& rhs);
    ...
    };

    where:

    Code:
    MyClass& MyClass::operator =(const MyClass& rhs)
    {
      // Assign all contents form rhs to 'this'
      ...
      ...
      return *this;
    }
    Last edited by Davros; 11-07-2002 at 06:18 AM.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. Problem with overloaded operators, templates and inheritance
    By bleakcabal in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2004, 04:07 AM
  3. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 08:40 PM
  4. overloaded operators
    By ivandn in forum C++ Programming
    Replies: 2
    Last Post: 12-20-2001, 02:52 PM
  5. help with overloaded operators
    By doleman19 in forum C++ Programming
    Replies: 23
    Last Post: 10-23-2001, 02:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21