C++ : what is :: for?

前端 未结 5 978
名媛妹妹
名媛妹妹 2020-12-14 16:40

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

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 16:52

    Lets say you have two versions of a function f() one defined outside a namespace and one defined inside. Now lets say you have one more function g() in the same namespace. Now if you do f() inside g() it will call the one defined in the same namespace. But if you want to call the global version you need to do ::f()

提交回复
热议问题