DONT_SET_USING_JUCE_NAMESPACE and auto-generated code

I created a little "hello world" type project and added an extra GUI component called "TestComponent" to it. The component has a TextButton and two ToggleButtons in it.

 

I prefer to make all my code very explicit about what it's doing, which means I prefer to make "using namespace" statements rarely, and only in very localized code blocks. I saw in one of the JUCE main headers that you can set the DONT_SET_USING_JUCE_NAMESPACE preprocessor directive to disable the global "using namespace juce;" declaration in that header. Sure enough, when I add DONT_SET_USING_JUCE_NAMESPACE=1 to my global preprocessor directives in the IntroJucer, my compilers don't recognize juce objects without juce:: in front of them. So far, so good.

 

The problem is that when I save the project, all the "juce::" statements that I added to the TestComponent unit in order to make it compile get removed.

Yeah, the GUI generator won't add explicit namespaces, you'd need to put your own using declaration into that file if that's what you want to do.

But that's not what I want to do. I don't want using namespace declarations in any of my files.

Well, looks like the Introjucer's GUI editor unfortunately doesn't support the juce:: in front of the classes it uses in its own generated code, so you'll have to use using namespace declarations at least in those files.

If I remember right, those auto-generated files includes some headers. Obviously I don't want to put "using namespace ..." in a header, because then it will propagate anywhere it is included. I think I will just put any JUCE components I add inside the juce namespace, that way other juce stuff is local to them.

EDIT: [url=http://coliru.stacked-crooked.com/a/39aeb869b4c52808]looks like[/url] if I put the components in a separate namespace I can put "using namespace juce;" inside that namespace and it won't propagate out. But I don't know if that is actually portable or compliant with the standard.

I modified the old jucer to generate fully qualified names, hence removing the need for the using directive. If someone is interested, send me a PM. I tested it and it seems to work

Disclaimer : this has nothing to do with Juce or Roli and I can’t guarantee that there aren’t any bugs .