Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double colon - Not sure what for 2

Status
Not open for further replies.

imagenetics

Programmer
Dec 8, 2003
66
PL
I have a question about functions preceded with double colon ("::"). Sometimes I find two source files and in one of them the function is preceded with double colon while in other file the same function is not. In both cases the result of the function is the same.

What is the difference between, fo example int someValue = ::GetValue(); and int someValue = GetValue();?
 
you meant

int someValue = AnyClass::GetValue();
and int someValue = GetValue();


the first case is used when you don't want to make an instance of the class


and the second one is used when you have an instance of the class
 
I've found the same issue with

AnyClass.GetValue();
AnyClass->GetValue();

I dont try to figure it out, but I
just keep in mind if the first dont
work the second will or versa vice.
I think I usuallly run into this if
I am accessing a class that is one
of the arguments to a function.

I'm sure the explanation is similiar
to what ginka replied.

tomcruz.net

 
Code:
obj->member
is equivalent to
Code:
(*obj).member

In other words, the [tt]->[/tt] operator is used when [tt]obj[/tt] is a pointer to the thing with the member. The [tt].[/tt] operator is used when [tt]obj[/tt] is the thing with the member.


Concerning the double colon:
Code:
::func();
explicitly calls the function [tt]func[/tt] that's in the global namespace. That might be useful if you have another function or local variable named [tt]func[/tt] that would be called if you only used
Code:
func();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top