Sign in to follow this  

Scope Operator Question

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know scope and everything but why do people do this:
//In some class...

void* operator new(int ammount)
{
  return ::new char(ammount); //What does this, "::", do?
}

It's not perfect source, but I think it gets the point across. Since it's already in class scope, why do you :: it?

Share this post


Link to post
Share on other sites
nothing preceeding the :: means use the global namespace.

[edit:]

#include <iostream>

using namespace std;

void moo(){
cout << "moo\n";
}

struct cow{
void moo(){
cout << "moo moo moo.\n";
}
void operator()(){
::moo();
}
};

int main(){
cow betsy;

betsy(); // calls the operator(), which calls the global moo,
// not cow::moo, thus printing one mere "moo"
}

Share this post


Link to post
Share on other sites

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this