Hi,
I'm trying to use a global array declared in a .h file. The array is marked as static and defined in the .cpp file.
I have a macro which gets the size of the array and is defined as such
Code:
#define sizeof_array(x) (sizeof(x)/sizeof(*x))
but when I try to use this function in the code below I get the following error :
Code:
bool contains(string,string[],int);
bool isArithemetic(string first) { return contains(first,cmd_arm,sizeof_array(cmd_arm));
Code:
error C2070: 'std::string []': illegal sizeof operand
This only happens if i declare it as extern, however if I dont, I get a linker error static multiply defined symbols. Here is my header and cpp containing the array -
Code:
//commands.h
#ifdef DEFINE_GLOBALS
#define GLOBAL
#else // !DEFINE_GLOBALS
#define GLOBAL extern
#endif
#define sizeof_array(x) (sizeof(x)/sizeof(*x))
#include <string>
using namespace std;
GLOBAL string cmd_arm[];// = { "+", "-" , "*" ,"/" , "sin", "cos","sqrt" };
Code:
//commands.cpp
#define DEFINE_GLOBALS
#include "Command.h"
string cmd_arm[] = { "+", "-" , "*" ,"/" , "sin", "cos","sqrt" };
Does anyone know how I can fix this ? or a better way to have a global array ? thanks!