I am beginer in C++ programing language and i want to learn how to use all my variables in every single part of project in C++ (separate .cpp files or classes...). For example, if we make comparation to Fortran, in Fortran we can make declaration or definition of variables in one module and we can use that module for sharing variables in main program or any other module. What concept from C++ is equivalent to concept of modules in Fortran?
我是C ++编程语言的初学者,我想学习如何在C ++的每个项目中使用我的所有变量(单独的.cpp文件或类......)。例如,如果我们与Fortran进行比较,在Fortran中我们可以在一个模块中声明或定义变量,我们可以使用该模块在主程序或任何其他模块*享变量。 C ++中的哪些概念等同于Fortran中的模块概念?
1 个解决方案
#1
0
The C++ equivalent to Fortran's modules is namespaces.
与Fortran模块等效的C ++是名称空间。
Have a look over there to learn more about namespaces.
查看那里以了解有关命名空间的更多信息。
Namespace introduces the idea of scope:
Namespace引入了范围的概念:
namespace V { // original-namespace-definition for V
void f(); // declaration of V::f
}
void V::f() {} // definition of V::f
void f() {} // declaration and definition of f() # different from V::f()
#1
0
The C++ equivalent to Fortran's modules is namespaces.
与Fortran模块等效的C ++是名称空间。
Have a look over there to learn more about namespaces.
查看那里以了解有关命名空间的更多信息。
Namespace introduces the idea of scope:
Namespace引入了范围的概念:
namespace V { // original-namespace-definition for V
void f(); // declaration of V::f
}
void V::f() {} // definition of V::f
void f() {} // declaration and definition of f() # different from V::f()