Java packages vs. C++ libraries

后端 未结 6 1865
死守一世寂寞
死守一世寂寞 2021-01-18 08:52

In Java, there is what is called package. Does library in C++ represent the same meaning, especially in terms for example

6条回答
  •  半阙折子戏
    2021-01-18 09:07

    There are different dimensions of what a package means in Java. As a container that differentiates the names of the classes inside from the names of classes in other packages, its equivalent would be c++ namespaces.

    As a unit that guarantees access to non-private members to classes in the same block, there is no equivalent in C++. The access level granted to a class is independent of the namespace where the class is defined.

    As a way of ordering your sources in the disk, there is no equivalent, the C++ language has no requirements on how the code is stored in files.

    Regarding c++ libraries, that is closer to jar files in Java. They bundle different classes that share some relation. A jar can contain more than one package, and more than one jar can contain classes from the same package. Similarly with libraries, they can contain classes from different namespaces and/or different libraries can contain classes from the same namespace.

提交回复
热议问题