#Why Would CpP needs 2 accessor, `::` and `.` ?
17 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
:: is for static, . is for non-static
:: is also used to refer to things outside of expressions (and therefore statically)
Ie you can get the address of a member function by doing &Foo::func
As for why it was separated like this, I am not sure... I imagine that early in C++'s design, Bjarne wanted to clearly separate what was a C-style access of a member vs the new feature he introduced (static scoping)
;compile cpp #include<iostream> struct b{ int c; }; struct A:b{ b b; }; int main(){ A a{1,2}; std::cout<<a.b::c<<'\n'; std::cout<<a.b.c<<'\n'; }
1
2
you can create situations where the difference is necessary
That says it all, for identifier shadowing, thank you.
@vocal sparrow Has your question been resolved? If so, type !solved :)
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
I doubt this was designed to support the one corner case volatile mentioned tbh
More likely it's what DXPower said. And this case just happened to benefit from it
in retrospect there is an even better reason:cpp int x; struct S{int x;}; S a{.x=42};//designated initializer S b{::x=42};//assignment in normal aggregate initialization