I have a C-function called "count" that looks like this:
void count(){
static int c = 0;
printf("Counter=%i", c);
c++;
}
Futhermore I have a vector of Cpp-objects and each object calls the "count" function. Since the counter variable is static a call made by one object will increase the counter value for all other objects as well. What I actually want is a dedicated counter for each object given the restrication that the "count"-function is Device-Under-Test and may not be changed. I think this should be possible using namespaces... Any ideas?
My initial idea was to use namespaces ...
namespace c1 {
#ifdef __cplusplus
extern "C" {
#endif
#include "count.h"
#ifdef __cplusplus
}
#endif
}
namespace c2 {
#ifdef __cplusplus
extern "C" {
#endif
#include "count.h"
#ifdef __cplusplus
}
#endif
}
And call from within Cpp-Object like this ...
if (objNr == 1) c1::count();
else if (objNr == 2) c2::count();
...
It did not work for me. Any idea why?