It has been a while since I transfer from Fortran to C++. Fortran is very good at making easy to write HPC code. The ability of module is so easy to use. However C++ involves a lot of class and object stuff which annoys me..
1. Single file program solution However, a quick and dirty way for declaring global variable for a single file program, is just simply declare variable before the main function. 2. Multi file program solution However, I found an article talking about global variables using namespace to define a subdomain where constants can be achieved as long as you call the cpp function and the extern command for those variables. But remember, not to using global variable arrays like you do in fortran, because C++ seems to be really don't like this way..Because fortran don't have reference method to pass a large variable. Another note is that namespace shouldn't be defined after "using namespace..." Ref http://www.learncpp.com/cpp-tutorial/42-global-variables/ |
AuthorShaowu Pan Archives
December 2017
Categories
All
|