I am writing a finite element code and I want my code works for both 2d and 3d applications. I am writing the code using OOP method and I have several classes and headers. I am trying something like
1 2 3 4 5 6 7 8
define dim 2
define nElmNodes 3
define dim 3
define nElmnodes 4
I don't know whether should I make .h file for this and include in every class which uses dim as a variable or put it in main file. I would be really grateful if you help me with this.
just make the 2d / 3d flag be a class member that you set on construction. Then each variable instance can be whatever it needs to be. You can even make interface type wrappers that inherit this thing and their default ctor can configure it to be 2d or 3d so you have friendly names like thing2d() and thing3d() ... not required, but a fancy approach.
AA, I am saying that with #defines he locks one compile into 2d or 3d mode, unless he does even more weirdness and undefines/redefines them on the fly everywhere which would be a horrible way to have to use the tool.