Nested namespaces by classes

It is possible to nest a namespace inside another namespace.

Classes, structs and unions are also namespaces, despite they have other purpose.

Theoretically it should be possible to nest namespaces inside classes, structs and unions, what could be very useful.

For example:

When several class members require the same variables, it would be useful for the programmer to use nested namespaces to avoid the re-declaration of the same variables.

It can also help compilers to optimize the code.

Personally I like to avoid the re-declaration of the same variables inside different scopes, because sometimes they are too much.

I don't like either let them easily accessible.

When it is easy to access them, it is possible to use them accidentally, what can cause problems, which sometimes require hours to be found, because they are hard to see.

Without nested namespaces by classes, I prefer to re-declare the same variables inside each scope to avoid confusions, despite it is an avoidable tedious task.

On these cases, it would be easier to write: using namespace name; inside the scope than to re-declare the same variables again.

It would also ease the identifying of scopes with shared variables.

Other reason to suggest this improvement is that it would allow to mix nested namespaces with templates.


/* author: ncomputers.org */
template<typename Typename>
struct Struct{
    namespace shared{
        Typename variable;
    }

    Struct():
        shared::variable(0)
    {}

    void Function_1(){
        //shared variable is visible
        using namespace shared;
    }

    void Function_2(){
        //use special variable
        int variable;
    }

    void Function_3(){
        {
            //shared variable is visible
            using namespace shared;
        }
        //use special variable
        int variable;
    }
};