void vs void::

are the following 2 piece of code same, because they are both compiling fine ...

1
2
3
4
5
 //1
void class1::function1(){ }
//2
void::class1::function1(){ }
Style preference, 99% of people use #1 though.
I have never used the second one, and almost never see it. Personally, it looks a little counter-intuitive (but that's just me).
"void::class1" makes me think of a class called "void" and a function called "class1" (we, of course, can't have a function called "void").
I believe what is actually being parsed for the second is:
void ::class1::function(){ }
where you are accessing the global namespace as opposed to the current one. They are not identical in meaning unless the first is already in the global namespace.
Topic archived. No new replies allowed.