Can a class share a namespace's name?

前端 未结 3 1624
旧时难觅i
旧时难觅i 2020-12-16 11:50

Is the following C++ code valid?

namespace Foo
{
    class Bar
    {
        // Class code here.
    };
}

namespace Foo
{
         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 12:23

    You cannot have the arrangement you have in your question because there is no way to disambiguate Bar.

    My compiler says:

    error C2757: 'Bar' : a symbol with this name already exists and therefore this name cannot be used as a namespace name
    

提交回复
热议问题