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

D

deanfamily

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

puzzlecracker

deanfamily said:
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) ?
 
D

deanfamily

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.
 
J

Jonathan Mcdougall

deanfamily said:
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
 
P

puzzlecracker

deanfamily said:
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.

I second it. Perhaps, computer science is not really for you. Can you
still change the major?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top