A
Andrea Crotti
I have the following situation:
I need to get some global variables from the outside (configuration
file) and keep them somewhere globally accessible. (For reading the
files I might use boost:rogram_options.)
So I did something like:
--8<---------------cut here---------------start------------->8---
#ifndef GLOBALS_H
#define GLOBALS_H
#include <iostream>
#include "Environment.h"
namespace GLOBALS
{
static int num_landmarks;
static int trace_length;
static int history_size;
static int distribution_size;
static Environment *environment;
// see why this error
static ostream *out;
}
#endif /* GLOBALS_H */
--8<---------------cut here---------------end--------------->8---
But actually it doesn't work, since if I do in one class
GLOBALS::history_size = 10;
in another class that value is still 0.
So I guess it doesn't work.
I also want to do something less stupid than a global state, but as long
as I don't understand very well the problem and how is best to construct
objects it would be the easiest way.
But what's wrong with this approach?
I need to get some global variables from the outside (configuration
file) and keep them somewhere globally accessible. (For reading the
files I might use boost:rogram_options.)
So I did something like:
--8<---------------cut here---------------start------------->8---
#ifndef GLOBALS_H
#define GLOBALS_H
#include <iostream>
#include "Environment.h"
namespace GLOBALS
{
static int num_landmarks;
static int trace_length;
static int history_size;
static int distribution_size;
static Environment *environment;
// see why this error
static ostream *out;
}
#endif /* GLOBALS_H */
--8<---------------cut here---------------end--------------->8---
But actually it doesn't work, since if I do in one class
GLOBALS::history_size = 10;
in another class that value is still 0.
So I guess it doesn't work.
I also want to do something less stupid than a global state, but as long
as I don't understand very well the problem and how is best to construct
objects it would be the easiest way.
But what's wrong with this approach?