Trying to pass values of variables from a redefined function into another function

Discussion in 'C++' started by deanfamily, Oct 23, 2005.

  1. deanfamily

    deanfamily Guest

    Here's the problem:
    I have a function that references another one in this manner:
    class circleType: public pointType
    so, pointType is redefined by circleType, thereby giving circleType access
    to all the functions in pointType if need-be. Here is the function I am
    using in pointType:

    void pointType::setCoords(double xCoord, double yCoord)
    {
    pointX = xCoord;
    pointY = yCoord;
    }

    it is being accessed in circleType in this manner:

    void circleType::getCoords(double xCoord, double yCoord)
    {
    //set the external point using the pointType header
    pointType::setCoords(pointX, pointY);
    cout << "The coordinate entered is: (" << pointX << "," << pointY << ")";
    cout << endl;
    }

    My cout works, but the point it prints is (0,0), meaning that the variables
    aren't being passed into the function, and it is just defaulting to the
    value of 0 for both.

    Any thoughts?
    deanfamily, Oct 23, 2005
    #1
    1. Advertising

  2. deanfamily wrote:
    > Here's the problem:
    > I have a function that references another one in this manner:
    > class circleType: public pointType
    > so, pointType is redefined by circleType, thereby giving circleType access
    > to all the functions in pointType if need-be. Here is the function I am
    > using in pointType:
    >
    > void pointType::setCoords(double xCoord, double yCoord)
    > {
    > pointX = xCoord;
    > pointY = yCoord;
    > }
    >
    > it is being accessed in circleType in this manner:
    >
    > void circleType::getCoords(double xCoord, double yCoord)
    > {
    > //set the external point using the pointType header
    > pointType::setCoords(pointX, pointY);
    > cout << "The coordinate entered is: (" << pointX << "," << pointY << ")";
    > cout << endl;
    > }
    >
    > My cout works, but the point it prints is (0,0), meaning that the variables
    > aren't being passed into the function, and it is just defaulting to the
    > value of 0 for both.
    >
    > Any thoughts?




    Code isn't very descriptive but seem as though you're passing
    uninitialized member variables of the pointType to PointType:

    void circleType::getCoords(double xCoord, double yCoord)
    {
    //set the external point using the pointType header
    pointType::setCoords(pointX, pointY);

    ....


    did you mean: pointType::setCoords(xCoord, yCoord) ?
    puzzlecracker, Oct 23, 2005
    #2
    1. Advertising

  3. deanfamily

    deanfamily Guest

    Even with it corrected to
    void circleType::getCoords(double xCoord, double yCoord)
    {
    //set the external point using the pointType header
    pointType::setCoords(xCoord, yCoord);
    cout << "The coordinate entered is: (" << pointX << "," << pointY << ")";
    cout << endl;
    }
    it still isn't passing the amounts.

    "puzzlecracker" <> wrote in message
    news:...
    >
    > deanfamily wrote:
    >> Here's the problem:
    >> I have a function that references another one in this manner:
    >> class circleType: public pointType
    >> so, pointType is redefined by circleType, thereby giving circleType
    >> access
    >> to all the functions in pointType if need-be. Here is the function I am
    >> using in pointType:
    >>
    >> void pointType::setCoords(double xCoord, double yCoord)
    >> {
    >> pointX = xCoord;
    >> pointY = yCoord;
    >> }
    >>
    >> it is being accessed in circleType in this manner:
    >>
    >> void circleType::getCoords(double xCoord, double yCoord)
    >> {
    >> //set the external point using the pointType header
    >> pointType::setCoords(pointX, pointY);
    >> cout << "The coordinate entered is: (" << pointX << "," << pointY <<
    >> ")";
    >> cout << endl;
    >> }
    >>
    >> My cout works, but the point it prints is (0,0), meaning that the
    >> variables
    >> aren't being passed into the function, and it is just defaulting to the
    >> value of 0 for both.
    >>
    >> Any thoughts?

    >
    >
    >
    > Code isn't very descriptive but seem as though you're passing
    > uninitialized member variables of the pointType to PointType:
    >
    > void circleType::getCoords(double xCoord, double yCoord)
    > {
    > //set the external point using the pointType header
    > pointType::setCoords(pointX, pointY);
    >
    > ....
    >
    >
    > did you mean: pointType::setCoords(xCoord, yCoord) ?
    >
    deanfamily, Oct 24, 2005
    #3
  4. deanfamily wrote:
    > Here's the problem:
    > I have a function that references another one in this manner:
    > class circleType: public pointType


    This means nothing. Be careful to use the correct terms for the
    concepts. What's more, some code is worth a thousand words, so they
    say.

    > so, pointType is redefined by circleType, thereby giving circleType access
    > to all the functions in pointType if need-be. Here is the function I am
    > using in pointType:
    >
    > void pointType::setCoords(double xCoord, double yCoord)
    > {
    > pointX = xCoord;
    > pointY = yCoord;
    > }
    >
    > it is being accessed in circleType in this manner:
    >
    > void circleType::getCoords(double xCoord, double yCoord)


    get or set?

    > {
    > //set the external point using the pointType header
    > pointType::setCoords(pointX, pointY);
    > cout << "The coordinate entered is: (" << pointX << "," << pointY << ")";
    > cout << endl;
    > }
    >
    > My cout works, but the point it prints is (0,0), meaning that the variables
    > aren't being passed into the function, and it is just defaulting to the
    > value of 0 for both.


    Something on line 42, perhaps?

    Seriously, the code you gave is obviously correct, so some wild
    guesses:
    1) circleType also has members named pointX and pointY which takes
    precedence over pointType's in the std::cout
    2) you passed 0,0 when you called getCoords (or setCoords?)
    3) another thread modify the variables
    4) main returns void
    5) you have a virus

    What does the debugger says? Is there more code to this program?
    Something we could test ourselves?


    Jonathan
    Jonathan Mcdougall, Oct 24, 2005
    #4
  5. deanfamily wrote:
    > Even with it corrected to
    > void circleType::getCoords(double xCoord, double yCoord)
    > {
    > //set the external point using the pointType header
    > pointType::setCoords(xCoord, yCoord);
    > cout << "The coordinate entered is: (" << pointX << "," << pointY << ")";
    > cout << endl;
    > }
    > it still isn't passing the amounts.
    >
    > "puzzlecracker" <> wrote in message
    > news:...
    > >
    > > deanfamily wrote:
    > >> Here's the problem:
    > >> I have a function that references another one in this manner:
    > >> class circleType: public pointType
    > >> so, pointType is redefined by circleType, thereby giving circleType
    > >> access
    > >> to all the functions in pointType if need-be. Here is the function I am
    > >> using in pointType:
    > >>
    > >> void pointType::setCoords(double xCoord, double yCoord)
    > >> {
    > >> pointX = xCoord;
    > >> pointY = yCoord;
    > >> }
    > >>
    > >> it is being accessed in circleType in this manner:
    > >>
    > >> void circleType::getCoords(double xCoord, double yCoord)
    > >> {
    > >> //set the external point using the pointType header
    > >> pointType::setCoords(pointX, pointY);
    > >> cout << "The coordinate entered is: (" << pointX << "," << pointY <<
    > >> ")";
    > >> cout << endl;
    > >> }
    > >>
    > >> My cout works, but the point it prints is (0,0), meaning that the
    > >> variables
    > >> aren't being passed into the function, and it is just defaulting to the
    > >> value of 0 for both.
    > >>
    > >> Any thoughts?

    > >
    > >
    > >
    > > Code isn't very descriptive but seem as though you're passing
    > > uninitialized member variables of the pointType to PointType:
    > >
    > > void circleType::getCoords(double xCoord, double yCoord)
    > > {
    > > //set the external point using the pointType header
    > > pointType::setCoords(pointX, pointY);
    > >
    > > ....
    > >
    > >
    > > did you mean: pointType::setCoords(xCoord, yCoord) ?
    > >


    I second it. Perhaps, computer science is not really for you. Can you
    still change the major?
    puzzlecracker, Oct 24, 2005
    #5
    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. Wei Li

    function redefined problem

    Wei Li, Aug 25, 2004, in forum: C Programming
    Replies:
    11
    Views:
    683
    Wei Li
    Aug 27, 2004
  2. erikcw
    Replies:
    3
    Views:
    229
    Bruno Desthuilliers
    Apr 2, 2007
  3. Replies:
    9
    Views:
    914
  4. MiG
    Replies:
    8
    Views:
    132
    Ryan Leavengood
    Oct 19, 2005
  5. soni2926
    Replies:
    4
    Views:
    98
    William James
    Nov 21, 2008
Loading...

Share This Page