I used the following approach to register functions, but you can try applying it in your case, I hope it guarantees this C-style workaround that does not take into account spaces:
#define GET_COMBO_BOX(x,y) x ## y for (int i = 1; i < numberOfBoxes; i++) GET_COMBO_BOX(comboBox1,i);
This clearly will NOT do what you want, since I am determined at compile time, and the macro is spent on preprocessing, but it will give you an idea of ββhow to pre-generate function calls.
Here is a more complete example of where macro concatenation is used:
#include<iostream> #include<string> using namespace std; template< class E > struct EnumNames { static const char* const* names; static int names_size; }; #define REGISTER_ENUM( e ) \ const char* const* EnumNames< e >::names = e ## _names; \ int EnumNames< e >::names_size = sizeof( e ## _names ) / sizeof( const char* ); enum ElementType { NEURON, SYNAPSE }; const char* const ElementType_names[] = { "N", "S" }; REGISTER_ENUM( ElementType ) enum TokenMainType { EP, IP, NT, AI }; const char* const TokenMainType_names[] = { "EP", "IP", "NT", "AI" }; REGISTER_ENUM( TokenMainType ) template<class E> ostream& operator <<(ostream& os, const E& e) { if (e > EnumNames< E >::names_size) cout << "Error" << endl; os << EnumNames< E >::names[e]; return os; } template<class E> istream& operator >>(istream& is, E& e) { std::string tmp_e_string; is >> tmp_e_string; for (int i = 0; i < EnumNames< E >::names_size; ++i) { if (tmp_e_string == EnumNames< E >::names[i]) { e = E(i); return is; } } cerr << "Fehler: tmp_nntype_string: " << tmp_e_string << endl; return is; } int main (int argc, char **argv) { ElementType test1(NEURON); cout<<string(EnumNames<ElementType>::names[test1])<<endl; }
Sasha
source share