Ah, I see what you mean.
Declare the function in your .h file
|
void print(double myDouble);
| |
and then, in your .cpp file
1 2 3 4
|
void print(double myDouble)
{
cout << myDouble << endl;
}
| |
That's all you need to do for the definition.
When you call the function, do it like this:
print(manipulate())
Since this is a class, and both "print" and "manipulate" are member functions of this class, you can solve this in a multitude of ways.
If you're working with an instance of your class (you created an object in main)
1 2 3 4 5 6 7
|
int main()
{
Temporary myTemp;
myTemp.print(myTemp.manipulate());
return 0;
}
| |
Or you could do it like you did before, that way also works perfectly:
1 2 3 4
|
void Temporary::print(){
//print values of the instance variables and the values returned by manipulate
cout << Temporary::manipulate();
}
| |
I haven't actually sifted through all of your code, so you might have to adjust that to make it work with your definitions. But for the principles, that's fine. When you call "print" (the one with "double" in the parenthesis) all "print" wants is a double - it doesn't care where it came from. Since "manipulate" returns a double, "print" can take that double and do whatever it wants with it.
It's like you have a factory that's making, let's say, apple sauce. That factory needs apples, but if you're just making apple sauce, you can use apples from anywhere, they just have to be apples. If something gives you an apple, you can use it to make apple sauce.
Your function "print" is like that apple sauce factory. It needs a double, but it doesn't care where it came from. Your function "manipulate" is like a farmer that sells their apples - it provides apples to the factory.
Think about that. In your function definition and declaration, you don't have to tell "print" where the double is coming from, it just needs to know that it is a double. The apple seller doesn't have to tell the factory where the apple came from (OK, in the real world, yes, but this is the programming world, where factories don't question where apples come from). The apple seller just has to make sure it gives the factory an apple, just like "manipulate" just has to return a double so that "print" can use it.