Jump to content
  • Advertisement
Sign in to follow this  
dbzprogrammer

Scope Operator Question

This topic is 4603 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!