Operation c++



  • Where and how can the operation be used?



  • :: is the operator used to specify (qualification) names.

    Binary operator :: Specify the area where the name is located.
    On the left side, the area of visibility shall be indicated, on the right side, by a specified name.
    The area of visibility may be the area of the name (namespace) or type.

    namespace NamespaceName {
      struct TypeName {
        typedef int NestedType;
      };
    }
    NamespaceName::TypeName a;  // имя TypeName находится в пространстве имен NamespaceName
    NamespaceName::TypeName::NestedType b; // имя NestedType находится в типе NamespaceName::TypeName
    decltype(a)::NestedType c; // имя NestedType находится в типе-результате decltype(a)
    

    Drug operator :: indicates that the name is in the global domain of names.

    int x;
    int main() {
      int x;
      return ::x; // Глобальная переменная
    }
    

    Also for operators . and ->After :: a key word may be indicated templateto show that the code further uses the template:

    struct X {
      template<int>
      static void f();
    };
    template<class T>
    void g() {
      T::f<1>(); // Ошибка: "<" означает оператор меньше
      T::template f<1>(); // ОК, используется шаблон f<1>
    }
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2