What is structural scope of a type T?

76 Views Asked by At

I found about it on wikipedia :

structural scope of T (which can be used to locate friend functions)

Could someone please explain what is it? Google was not of much help.

1

There are 1 best solutions below

2
On

Since it mentions friend lookup, "structural scope" in this case appears to refer to scope of class T (when T is a class) or the scope of enclosing class (when T is a member type declared inside a class). The wording of that entire paragraph sounds rather strange, since C++ language does not formally refer to class types as "structure types" and does not formally define "structural scope". On top of that it seems to refer to class scope as "namespace", which is incorrect.

By mentioning friends, it apparently implies situations like

struct T {
  friend void foo(T) {}
};

int main() {
  T t;
  foo(t);
}

or

struct T {
  enum E { A };
  friend void foo(E) {}
};

int main() {
  T::E e = T::A;
  foo(e);
}

In these cases calls to foo in main are possible to resolve only because ADL checks the scope of class T and explicitly looks for friend functions there. Without ADL, foo would be invisible to main.