create a namespace in c++/cli?

霸气de小男生 提交于 2019-12-24 02:52:17

问题


I have seen many examples of using .NET Framework namespaces in c++/cli like the following:

using namespace System;
using namespace System::IO;

But I haven't seen any examples of creating my own. So I was wondering if there is a way to declare/create my own namespace as I would in C#:

namespace Animals
   {

   public class Dog
       {
       public Dog() {}
       }
   }

Thanks for your time :)


回答1:


Same syntax for single namespaces. Nest for multiples, e.g. for First.Second.Third:

namespace First
{
namespace Second
{
namespace Third
{

    // Your code

}
}
}

In C# the same would be:

namespace First.Second.Third
{
}



回答2:


You already know how it should be done, as is demonstrated by your example

namespace NamespaceName //C++/CLI or C#
{
    //contents
}


来源:https://stackoverflow.com/questions/6681175/create-a-namespace-in-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!