c++ - doubts regarding usage of :: (scope_resolution_operator) -


when studying book on c++, came across this. if declare class,

class student {public: void func(int v1,int v2) {    //some code } //some members. }; 

and use function same name out of class (non-member function) like,

void func(int x,inty) 

and if wish call non-member function in member function of above declared class, syntax be,

//inside member function... ::func(x,y); } 

correct me if wrong.otherwise, assuming wrote

using namespace std; 

in beginning of program, below code equivalent previous one?

//inside member function std::func(x,y); } 

and, answer change if use different namespace other std?? ie, provided use,

using namespace abc 

are following declarations

abc::func(x,y) 

and,

::func(x,y) 

absolutely equivalent under conditions or change under specific conditions??

thank you.

in beginning of program, below code equivalent previous one?

//inside member function   std::func(x,y); 

no isn't. because preform qualified name lookup. means specify in namespace func defined. std::func, if exists, still belongs the std namespace, not global one.

a using namespace directive makes identifiers available unqualified name lookup, it's compiler figure out. point quite intricate, know, it's reason namespaces can considered useful.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -