Parameters and include files

Actually, scrap what I said yesterday. The common situation still is: you have a set of parameters that are basically global to the program. But, of course, it is not good to go totally global. OK, I think the best idea is to define a class in a header file. Then, declare one of these classes in the header file as external. Then declare (for real) just once somewhere. Ideally a singleton class should be used, but this is a bit over my head, just remember to declare one of these classes (and just once). (Unless you do want several sets of parameters, who knows…)

The members of the funtion are all public, and contain the parameters. Plain static members don’t make much sense (since there will only be one of these classes), but constant data should be declared static const, and declared somewhere (globally).

So, for example:

file “defs.h”


using std::endl;
using std::cout;

class dta {

double f;

static const int i;


extern dta data;

Then, define stuff somewhere:

file “defs.cpp”


dta data;

const int dta::i=10;

void defs(void) {  data.f=0; }


file “main.cpp”


int main(void) {

cout << data.i << endl;
cout << data.f << endl;
cout << “Done” << endl;
return 1;

Just compile with g++ main.cpp defs.cpp.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s