Can a class share a namespace's name?

前端 未结 3 1615
旧时难觅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:30

    "can there be a namespace with the same name as a class?"

    No, If they are in the same namespace, as in your case.

    Otherwise, yes. Anything can have the same name as anything else if they are in different namespaces. See this stackoverflow thread as reference.

提交回复
热议问题