What is namespace used for, in C++?

后端 未结 4 1277
灰色年华
灰色年华 2020-12-03 06:09

What is namespace used for, in C++?

using namespace std;
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 06:25

    It's used for preventing name confilct, so you may have two classes with the same name in different namespaces.

    Also it's used for categorizing your classes, if you have seen the .net framework, you will see that namespaces are used for categorizing the classes. For example, you may define a namespace for the employee classes, and a namespace for the tasks classes, and both namespaces are within a namespace for the company classes, since a namespace may contain sub namespaces.

    The same namespace may exist in different files, so using it may be useful because it will make you able to directly use all the classes in the namespaces in every #included file.

    That's what I remember for now.

提交回复
热议问题