Results 1 to 3 of 3

Thread: overload

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    1

    overload

    given class sefinition:
    class A
    {
    public:
    //constructors
    // other members
    private:
    int x;
    int y;
    };

    Give declarations of operator functions for each of the following ways to overload operator+ you must state where the declaration goes, whether within the class in the public or private section or outside the class. The operator + may be overloaded
    a. as friend function
    b. as member function
    c. as non-friend, non-member function

    NExt week i have exam and this is one of the question in the samplepaper .Please solve it.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: overload

    Hey,

    This sounds a little bit like homework. I don't think many people here will be willing to help you out unless you show some willing as to answering the question yourself. What exactly about the above do you not understand?

    Gary

  3. #3
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: overload

    First off all.. That is C++.. This is a vb.net forum. We do have a C, C++ forum where you shouldve posted this.

    a friend function is a global function that has access to class members. Therefore the operator will be global. This will overload the + operator for the whole application (well in simplest terms).

    The member function will be inside the public section of the class. This overload will only work if overloading an object. For example overload the + is a unary operation. Therefore in your main() you can have this

    Code:
    myType x, a;
    a = +x
    or the - operator which means
    Code:
    myType x, a;
    a = -x
    however, IT DOES NOT OVERLOAD THIS:
    Code:
    myType x, y, z;
    z = x + y;
    To do that you must overload the binary operator.

    You can guess the third question. (hint it goes in the class but figure out which section)

    I highly recommend reading over your course outline/notes. If this is for an exam then you need to know this stuff really well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width