member function with no class name specified

J

John Goche

Hello,

I have come across the following directive but I don't see a class
name specified in front of the ::Check function. Does anyone
know what this means and how the directive is supposed to work?

#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)

Thanks,

JG
 
M

mlimber

John said:
Hello,

I have come across the following directive but I don't see a class
name specified in front of the ::Check function. Does anyone
know what this means and how the directive is supposed to work?

#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)

::Check is a function in the global namespace.

Cheers! --M
 
V

VJ

mlimber said:
::Check is a function in the global namespace.

Can it be used for functions in the nameless namespace? Or is it more
for global functions?

For example:

#include <iostream>
using namespace std;

namespace
{
void f()
{
cout<<"222222222222"<<endl;
}
}

int main()
{
::f();
}

This will print 2's
 
V

Victor Bazarov

VJ said:
Can it be used for functions in the nameless namespace? Or is it more
for global functions?

Yes, it can. Unnamed/nameless/anonymous namespace names are inserted
into the scope in which that namespace appears. The way anonymous
namespace

// some scope
namespace {
// some names declared
}

behaves is similar to

// some scope
namespace SomeWeIrD_and_UNIQUEnaME {}
using namespace SomeWeIrD_and_UNIQUEnaME;
namespace SomeWeIrD_and_UNIQUEnaME {
// some names declared
}

(see 7.3.1.1/1); only the weird and unique name is different for
every translation unit and is *not* available to the programmer.
For example:

#include <iostream>
using namespace std;

namespace
{
void f()
{
cout<<"222222222222"<<endl;
}
}

int main()
{
::f();
}

This will print 2's

.... As it should.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top