-
July 16th, 2014, 08:20 AM
#1
anonymous namespace qualifier
It has recently been brought to my attention that it is possible to use a namespace as a "qualifier" in the signature of a definition as opposed to using a block. EG:
Code:
//Begin declarations here
namespace ns
{
extern int i;
void foo();
void bar();
}
//Begin definitions here
int ns::i = 5;
void ns::foo(){...}
void ns::bar(){...}
I did not know this was possible before, and I like this a lot, because:
- It avoids a huge useless block/indent.
- More closely resembles how you'd use static class encapsulation.
What I'm wondering though is: Is it possible to do something similar for an anonymous namespace? A lot of my .cpp files have internal helper functions/objects "forward declared" in an anonymous namespace, and then implemented later. I've tried:
Code:
namespace
{
void helper();
}
//Begin implementations here
void helper(){...} //This is actually a brand new declaration
void ::helper(){...} //This doesn't compile
Is there any way to say: "This is the implementation for something declared in anonymous namespace", without actually opening a namespace block?
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|