Passing objects

This is a discussion on Passing objects within the C++ Programming forums, part of the General Programming Boards category; In main i'm declaring an object P: Point P; Then i'm trying to pass it and another Point object dest ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    13

    Passing objects

    In main i'm declaring an object P:

    Point P;

    Then i'm trying to pass it and another Point object dest to use the ojbects:

    int numOfPaths(Point P, int x, int y, Point dest, int n);

    numOfPaths(P, x, y, dest, n);


    Main.cpp is giving me no problems, but numOfPaths.cpp is giving me two errors, one for each of the Point objects.
    "Identifier "Point" is undefined" and it points to each of the Points at the top of the function.

    int numOfPaths(Point P, int x, int y, Point dest, int n)
    ^ ^
    {
    code for function
    }

    I'm pretty sure i'm passing the object wrong but I can't figure out how. Main compiles fine, so i'm not sure.

    My other question is about overloading the == operator to compare two Point objects.

    bool operator == (const Point &P) const;

    is how its written in a public class of Point.

    if(dest==P)

    is when i'm calling it in numOfPaths.cpp. dest and P are my two objects i'm trying to compare. In my coding for the operator == I have:

    bool Point:perator ==(const Point &P) const
    {
    bool result = false;

    if(x = P.x && y = P.y)
    result = true;
    return result;
    }

    x and y are coordinates. I'm trying too see if point P is at point dest yet, so after P moves i compare P and dest. I'm getting two compiler errors that say x and P.x "must be a modifiable lvalue".

    Thanks if you can help on either of these, i've already tried searching C++ board for passing objects but couldn't find anything related.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    PHP Code:
    bool Point:: operator ==(const Point &P) const 

    bool result false

    if(
    P.&& P.y
    result true
    return 
    result

    should be:

    PHP Code:
    bool Point:: operator == ( const Point) const 

    return ( ( 
    == P.) && ( == P.) ) 

    Your passing of objects is ok for now, your error seems
    to indicate you didn't include the headerfile for Point in the
    file your function is located in.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing local objects by reference
    By manav in forum C++ Programming
    Replies: 15
    Last Post: 03-31-2008, 07:32 AM
  2. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 12:08 PM
  3. passing objects
    By r0bbb in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2005, 12:10 PM
  4. Passing objects
    By xshapirox in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2004, 11:34 AM
  5. Passing Objects using menus
    By TankCDR in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2003, 10:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21