What does this scope resolution operator depict? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does this scope resolution operator depict?

Here's the code - #include <iostream> template <int N> struct Factorial { enum { value = N * Factorial<N - 1>::value }; }; template <> // specialization struct Factorial<0> { enum { value = 1 }; }; int main() { int x = Factorial<4>::value; // == 24 int y = Factorial<0>::value; // == 1 std::cout << x << " " << y; return 0; }

4th Nov 2020, 7:09 AM
Harshit Nema
Harshit Nema - avatar
2 Answers
+ 2
¶ Этот оператор показывает, что value обращается к пространству имён структуры Factorial. Тобишь как для указателя "- >" - только отличие в том, что этим операндом можно обращаться напрямую к функциям, для их вызова, а не только к переменным функции. ________________________________ std::cout ¶ Здесь тоже показано, что мы используем cout - из пространства имён std. А std - тоже класс, как тот, что ты создал (классы и структуры схожи и на них тоже это распространяется).
6th Nov 2020, 10:07 AM
Кайто Судзуки
Кайто Судзуки - avatar
+ 2
¶ This operator shows that value refers to the space of the features of the Factorial structure. Tobi's point as a pointer "->" - the only difference is that this operand can address directly to the functions, to call them, and not only to the variable function. ________________________________ std::cout ¶ It also shows that we use cout - from the space of the name std. And std is also a class like the one you created (classes and structures are similar and this applies to them too).
6th Nov 2020, 10:08 AM
Кайто Судзуки
Кайто Судзуки - avatar