I just wanted to know the difference between . operator and :: operator?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Another way to think of the quad-dot '::' is the
scope resolution operator.
In cases where there are more than one object in scope that have the same name. You explicitly declare which one to use:or
The dot operator '.' is to call methods and attributes of an object instance
It was not asked, but there is another operator to use if an object instance is created dynamically with
new
, it is the arrow operator '->'If you are using a pointer to an object instance, you'll have to access the members of the object using -> in place of "dot"
The former (dot,
.
) is used to access members of an object, the latter (double colon,::
) is used to access members of a namespace or a class.Consider the following setup.
In this case, to refer to the structure, which is a member of a namespace, you use
::
. To access the variable in an object of typetype
, you use.
.