New user, new to programming, x seconds of search didn't find me an answer. Whole code (incomplete - and an online quiz for basic stuff):
#include "stdafx.h"
#include <iostream>
#include "constant.h"
double towerheight()
{
std::cout << "Input tower height" << std::endl;
double height;
std::cin >> height;
return height;
}
double ballheight(double towerheight)
{
//valid stuff goes here in program, but not applicable to question
}
int main()
{
double towerheight;
towerheight = towerheight(); //Error occurs here
ballheight(towerheight);
return 0;
}
3 lines from bottom ignoring whitespace and closing bracket is where the error occurs. (term does not evaluate to a function taking 0 arguments.)
I'm sort of lost at the research end of this and could use some human help.
Apologies for potentially poor formatting. Please advise, I may not know certain terms responsible for the error, and my goal is to understand what's going on.
EDIT:
Solution for me was changing the name of the double variable above the error. Why did this become an issue?
In main, the variable named towerheight shadows the function towerheight. Hence,
towerheight = towerheight();
is not valid. It is analogous to calling a function on a variable.
double towerheight;
double dummy;
towerheight = dummy();
That's why it is not correct.
Solution 1
You can use:
double towerheight;
towerheight = ::towerheight();
Using ::towerheight works since it refers to the name in the enclosing namespace and not the locally defined variable of the same name.
Solution 2
Use different names.
You can avoid some of the confusion by using two different names.
double t_height = towerheight();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With