Thread: Function and Overloaded Operator Parameters

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    66

    Function and Overloaded Operator Parameters

    Alright I am reading Practical C++ and this is what I am confused about.
    struct Point2d
    {
    float x;
    float y;
    };

    Point2d operator-(const Point2d& p1, const Point2d& p2);
    Point2d Subtract(const Point2d& p1, const Point2d& p2);


    Point2d operator-(const Point2d& p1, const Point2d& p2)
    {
    Point2d pt;

    pt.x = p1.x - p2.x;
    pt.y = p1.y - p2.y;

    return pt;
    }

    Point2d Subtract(const Point2d& p1, const Point2d& p2)
    {
    Point2d pt;
    pt.x = p1.x - p2.x;
    pt.y = p1.y - p2.y;
    return pt;
    }

    later on it goes to

    Point2d pt1 = {10.0f, 16.0f};
    Point2d pt2 = {8.0f, 7.0f};

    Point2d pt3 = Sbutract(pt1, pt2);

    pt3 = pt1 - pt2;


    what I am wondering don't you have to pass the parameters in with the same name shouldn't pt1 and pt2 be p1 and p2??
    Last edited by aresashura; 12-05-2001 at 12:39 PM.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    No, functions use a local copy(or copy of the address) of a parameter so they can be any name you want inside the function as long as they're the same type.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-04-2008, 05:57 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Problem with overloaded function templates
    By New++ in forum C++ Programming
    Replies: 10
    Last Post: 09-05-2005, 04:00 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Cannot resolve overloaded function
    By Mithoric in forum C++ Programming
    Replies: 10
    Last Post: 11-29-2003, 03:40 AM