+ 2

:: vs : c++

What does the :: command do compared to the : command in c++ (classes and functions)?

21st Oct 2019, 10:12 PM
Brodie Evans
Brodie Evans - avatar
1 Odpowiedź
+ 7
:: is called scope resolution operator. It is used to identify scope of something. For example, if you have two namespaces where you declared function named `my_function`. When you call one of these functions, you use the scope resolution operator to tell the compiler which version of `my_function` you wanted to use, this increases scope clarity, which object is wanted and from which place. : In OOP, AFAIK means 'inherits' or 'extends' (don't know the exact name for this). But it is used in class/structure declaration where you specify that a certain class inherits/extends another class/structure. Example: class Child : public Parent : In function is used in enhanced for loop, for example: int int_array[] {1, 2, 3, 4, 5}; for(int val : int_array) std::cout << var << " "; This prints every element in array <int_array>. Most of these are covered in the lesson IIRC. Hth, cmiiw
21st Oct 2019, 11:18 PM
Ipang