By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?
Oct 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

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) ?

Oct 23 '05 #2

P: n/a
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" <ir*********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

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) ?

Oct 23 '05 #3

P: n/a
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

Oct 23 '05 #4

P: n/a

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" <ir*********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

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?

Oct 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.