Thread: Conversion and Constructor Functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Conversion and Constructor Functions

    Hi,
    Code:
    class X
    {
        int i;
    public:
        X(const int& val) : i(val)
        {}
        X operator+(const X&);
    };
    
    X X::operator+(const X &ob)
    {
         return X(i + ob.i);
    }
    
    int main()
    {
         X ob1(10), ob2;
        
         ob1 + 30; // this works like ob1 + X(30);
        
         30 + ob1; // NOT working in VC++. Any idea why???
    
         return 0;
    }
    Can any body throw any light as to why if
    ob1 + 30 works why not 30 + ob1

    thanks in advance,
    Last edited by shiv_tech_quest; 03-06-2003 at 01:20 AM.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

Popular pages Recent additions subscribe to a feed