• Advertisement
Sign in to follow this  

Scope Operator Question

This topic is 4420 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
Advertisement
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
Sign in to follow this  

  • Advertisement