If you go to the accepted answer of this post
Could someone please elaborate on why he uses:
double temp = ::atof(num.c_str());
and not simply
double temp = atof(num.c_str());
Also, is it considered a good practice to use that syntax when you use "pure" global functions?
An operator is a symbol that operates on a value or a variable. For example: + is an operator to perform addition. C has a wide range of operators to perform various operations.
In programming, an operator is a symbol that operates on a value or a variable. Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while - is an operator used for subtraction. Operators in C++ can be classified into 6 types: Arithmetic Operators.
It's called scope resolution operator. More information in Scope Resolution Operator (::) (PHP manual).
It says use the global version, not one declared in local scope. So if someone's declared an atof
in your class, this'll be sure to use the global one.
Have a look at Wikipedia on this subject:
#include <iostream> using namespace std; int n = 12; // A global variable int main() { int n = 13; // A local variable cout << ::n << endl; // Print the global variable: 12 cout << n << endl; // Print the local variable: 13 }
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