0

sin() defined in math.h @line:44, saying "using std::sin", but if I try to access sin directly by "using std::sin" I get error.

CODE 1: #include <iostream> using std::cout; int main() { cout << abs(-1) ; //OUTPUT: 1 !! return 0; } CODE 2: #include <iostream> using std::cout; int main() { cout << sin(0) ; //error: sin not declared return 0; } Even if I try, CODE 3: #include <iostream> using std::cout; int main() { cout << std::sin(0) ; //error sin not declared return 0; } sin() defined in math.h @line:44, saying "using std::sin", but if I try to access sin directly(without importing math.h) "using std::sin" I get error.

19th May 2017, 7:31 AM
Preet Patel
Preet Patel - avatar
4 ответов
0
@Preet Patel now the function in c++ of sin , have 2 editions in include files, the abs is "global" function, and sin has "global" edition(old C version) and c++ edition(std::sin), so you might use sin as a global function just like abs(the abs is "internal function" in some comilers, so you can use directly), (something like ::sin, or sin ), or use std::sin after you include the standard c++ library math file. if fail, try to include math.h to use old C version of sin, and cmath (depends on your compiler) to use std::sin
19th May 2017, 8:56 AM
DarkSpy
+ 1
#include <cmath> using std::sin; int main() { double x = sin(3.1416); }
19th May 2017, 10:35 AM
Testing002
0
i dont know which version of your compiler, as i can see, you were not include the header file which sin function defines. try to include the sin header file. might be the cmath or something, it's claim your compiler.
19th May 2017, 7:40 AM
DarkSpy
0
@DarkSpy I know how to overcome this problem, but I doubt what's exactly happening here, since in CODE 1 I didn't include abs() but then also, program compiled successful, now how come this be possible? As this doesn't hold true if I call any other math function except abs().
19th May 2017, 8:26 AM
Preet Patel
Preet Patel - avatar