educative.io

Educative

Explanation of fully qualified and current scope

I think the code snippet doesn’t match the explanation:

  • Introduce the name into the current scope: The expression using Base<T>::func2 (line 22) introduces func2 into the current scope.
  • Call the name fully qualified: Calling func3 fully qualified (line 27) will break a virtual dispatch and may cause new surprises.

Is it possible to explain this part in a little detail?

Thanks.

Hi @Arf

The first bullet point is talking about the use of the keyword using in line 22 of the code snippet to introduce func2 into the current scope. func2 is then called on line 26 by simply doing func2() since it’s already been introduced into the scope.

The second bullet point is referring to line 27, where the function is being called using its fully qualified name, as Base<T>::func3().

A fully qualified name is an unambiguous name that specifies which object, function, or variable a call refers to without regard to the context of the call.

Hope this helped!

1 Like

Thanks @Hafsa_Kamran. That explains it.