-2

In my class, we have been learning about the standard template library, and how you have to use std:: when using objects from the library, so the compiler knows you are specifying the standard namespace. For example, std::string That's understandable. Recently though, I have been seeing objects and types specified with string::. What exactly does the string:: mean? Is it part of some sort of string namespace? Why do you have to specify something that is already specified as part of the standard namespace, i.e the std::string. Also, where is the global namespace defined, and how does correlate with the standard namespace?

Thanks.

Art
  • 275
  • 2
  • 9
  • 2
    Possible duplicate of [Why does C++ need the scope resolution operator?](https://stackoverflow.com/questions/9338217/why-does-c-need-the-scope-resolution-operator) –  Feb 07 '18 at 04:13

1 Answers1

0

In this context, the :: refers to class members, e.g. string::npos.

It allows you to access static class members without creating an object.

It also allows you to access class members that have been overloaded by subclasses.

The global namespace is the default namespace. It has no name, and it contains everything that is not explicitly placed inside a named namespace.

Sid S
  • 6,037
  • 2
  • 18
  • 24