Here's a brainteaser:
I have some legacy C code that I cannot modify for various reasons. I
would like to be able to wrap this code into a C++ class so that I can
create multiple objects to interact with.
To simplify, here's some code:
================================================== ====
foo.h (Can't modify):
#ifndef _FOO_H_
#define _FOO_H_
#if defined(TEST1) && defined(TEST2)
#error "Cannot define both TEST1 and TEST2"
#endif
#ifdef TEST1
#define OUTVAR 1
#elif defined(TEST2)
#define OUTVAR 2
#else
#error "Need TEST1 or TEST2"
#endif
extern int testInt;
void testFunc();
#endif
================================================== ====
================================================== ====
foo.c (Cannot modify):
#include "foo.h"
#include <stdio.h>
int testInt;
void testFunc() {
testInt = OUTVAR;
printf("%d\n", testInt);
}
================================================== ====
To complicate matters further, I would like to have two different
object types, one where TEST1 is defined, and one where TEST2 is
defined, and I would like for each object to have their own copy of
global variables (like testInt).
Thanks in advance for your help!