Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Location
    kangaroos
    Posts
    294

    Overload function + Inheritance? :: plz Help

    Please help me with the Inheritance VTM. I'm a bit confuse still.

    Q1. We have 2 overload Multiply (*) operator function. Why 1 of them is part of the Point class while the other isn't ??

    Q2. When we have VectorA = VectorB * 4, or VectorA = VectorB + VectorC,
    The = assignment takes place first, evaluate VectorA, then the multiplication/addition is happen after that, using the new VectorA . am i right?


    Q3. We have overload the assignment operator "=". and it is part of the Point class.
    Point Point:perator =(Point &p)

    how come it works with Vector also?
    e.g VectorA = VectorB * 4; ?????
    or VectorA = VectorB;

    I thought the "=" operator receive Point, not Vector. They are 2 different object types don't they?

    Thank very much

  2. #2
    Join Date
    Jan 2004
    Location
    South Pole
    Posts
    1,519

    Re: Overload function + Inheritance? :: plz Help

    Originally posted by alexqwerty
    Please help me with the Inheritance VTM. I'm a bit confuse still.
    I'll try, but I haven't seen the VTM's and I don't have your source, so I don't know too much about what you're talking about..


    Q1. We have 2 overload Multiply (*) operator function. Why 1 of them is part of the Point class while the other isn't ??
    Usually it doesn't make much of a difference if the operator is part of the class or not; you can do it either way you like. Give me the source and I can try to explain more.

    Q2. When we have VectorA = VectorB * 4, or VectorA = VectorB + VectorC,
    The = assignment takes place first, evaluate VectorA, then the multiplication/addition is happen after that, using the new VectorA . am i right?
    No, you are not right! The assignment happens last. (Assignments happen after multiplication and addition, and are done from right to left.)

    [p]Q3. We have overload the assignment operator "=". and it is part of the Point class.
    Point Point:perator =(Point &p)

    how come it works with Vector also?
    e.g VectorA = VectorB * 4; ?????
    or VectorA = VectorB;

    I thought the "=" operator receive Point, not Vector. They are 2 different object types don't they?[/b]
    I can't really say much about this unless I see the source code. Usually, though, there is no difference between a point and a vector.. So I'm guessing that either they are the same thing, or there are copy constructors for making a Vector from a Point, or making a Point from a Vector.

    In any case, even if you don't define a "=" function yourself, the compiler will copy them anyway, by copying all the variables in the class.

Posting Permissions

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