Thread: how to use operator+() in this code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2005
    Location
    Lahore, Pakistan
    Posts
    6

    how to use operator+() in this code?

    Hi guys!

    I don't know anything about how to use operator+(), I have just searched some sites(tutorial / articles) and have done what they have said, but didn't succeeded in compiling my program.

    Here is the code, (commenting the lines used for operator+())
    Code:
    #include <iostream>
    using namespace std;
    
    class math
    {
        private:
        int number;
    
        public:
        math();   //constructor of the class
    
    //    math operator+(math);
    
    math::math()
    {
        number = 0;
    }
    
    int main()
    {
        math obj1, obj2;
    //    int a = 10;
    //    obj1 = obj2 +a;
        obj1 = obj2 + 10;
    }
    
    math math::operator+(math obj)    //Also wrote (math obj, int x) and many other combinations
    {
        math temp;
        temp.number = obj.number + 10;
        return (temp);
    }
    Compiler says that, there is no operator+ for 'obj2 + 10'
    Last edited by barlas; 07-08-2005 at 05:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM