if i do a friend Testclass operator +(Test class &obj2); it is not correct because i need two obj

Discussion in 'C++' started by John Cho, Mar 3, 2004.

  1. John Cho

    John Cho Guest

    if i do a friend Testclass operator +(Test class &obj2); it is not
    correct because i need two objects?
     
    John Cho, Mar 3, 2004
    #1
    1. Advertising

  2. "John Cho" <> wrote in message
    news:Xns94A0EEC2B51B0spockieverizonnet@199.45.49.11...
    > if i do a friend Testclass operator +(Test class &obj2); it is

    not
    > correct because i need two objects?


    It depends what you want to do. If you declare operator+ as above, you
    get a unary operator+ which might be used like this, for example (for
    illustration, I'm assuming you also have a binary operator*):

    Test a, b, c;
    c = +b * a

    If you want to be able to write

    c = a + b

    you need to define a binary operator+, which you might declare as
    follows:

    Test operator+(const Test&, const Test&);

    Jonathan
     
    Jonathan Turkanis, Mar 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    3
    Views:
    15,702
    Jay B. Harlow [MVP - Outlook]
    Aug 9, 2003
  2. Phil Endecott

    Obj* ptr = new Obj(X)

    Phil Endecott, Jun 3, 2005, in forum: C++
    Replies:
    5
    Views:
    465
    Mark P
    Jun 3, 2005
  3. alf
    Replies:
    9
    Views:
    408
  4. WittyGuy
    Replies:
    5
    Views:
    451
    James Kanze
    Apr 26, 2007
  5. SpringFlowers AutumnMoon

    Ruby's a = b vs PHP5's $obj1 =& $obj2

    SpringFlowers AutumnMoon, Sep 27, 2007, in forum: Ruby
    Replies:
    6
    Views:
    131
    7stud --
    Sep 27, 2007
Loading...

Share This Page