Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Anonymous Namespace + Refactorings

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
akhtar Posted - Jul 14 2008 : 1:56:27 PM
I have created an example of what I think is incorrect functionality.

namespace {
    // 1) Type the declaration
    void MyFunction();

    // 2) Right click "MyFunction", and apply the VAX Create Implementation refactoring
}


namespace {

}
    // 3) Note that the generated implementation is not in the existing anonymous namespace or wrapped in its own.

void MyFunction()
{

}
3   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Jul 15 2008 : 3:19:41 PM
That is interesting, thank you. Since anonymous namespaces clearly have a point and a use I have put in a bug report for this:

case=18502

As a temporary workaround you can use VA Outline to move the function implementations into the namespace.
mwb1100 Posted - Jul 15 2008 : 1:44:57 PM
quote:
Originally posted by feline


Does an anonymous namespace actually have any effect at all?


An anonymous namespace scopes the enclosed declarations to the current compilation unit (similar to using the variant of 'static' that prevents a name declared at file scope from having external linkage).

Some (most?) C++ experts suggest that an anonymous namespace should be used in preference to using the static keyword to keep items 'private' to the current compilation unit. I'm not entirely sure if there's any benefit other than it reduces the overloaded use of the 'static' keyword (which is actually a good enough reason for me, but not good enough to call out for other people's code).

When an anonymous namespace is used, there's an implicit 'using' directive that brings those names into scope for the compilation unit.

That's why the compilation works even when the definition of the function/variable is not enclosed in the namespace braces. So the code that VAX creates works, but I can understand that someone might want the definition to end up within the namespace. It would be my preference.

feline Posted - Jul 15 2008 : 10:33:16 AM
I am seeing the same effect, but this does not seem to matter. Using VS2005 I have added the following code to a header file:

namespace
{
	class testCreateImpClassAnonymousNamespace
	{
		void AnonymousMemberFunctionOne();
	};
}


and this code to the matching cpp file:

namespace
{
}

void testCreateImpClassAnonymousNamespace::AnonymousMemberFunctionOne() { }


and this compiles perfectly happily. As soon as I give the namespace in the header file a name the code no longer compiles.

Does an anonymous namespace actually have any effect at all?

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000