c++ - #define an array value with index -


for legacy reasons need maintain old array structure(s), compiler tells me there problem 'expression syntax'.

here's have:

#define array[globalindexvariable]    get(globalindexvariable)->subtype; 

get returns valid pointer struct, contains subtype

now imagined take every occasion of array[globalindexvariable] , convert function call, apparently mistaken.

i don't know search in context, little highly appreciated.

thank much.

edit: since asked, here 1 of lines throw error:

localvariable = array[globalindexvariable]; 

i wish stress, i'm not looking make macro, rather want replace array[globalindexvariable]; get(globalindexvariable), other globalindexvariable used, replacement fail , throw different error.

edit:

just make absolutely sure understood:

right have 4 long arrays of type int. want stuff these struct both mark belong (they describe different aspects of same thing) need bulk solution previous code fragments (a few thousand occurrences).

old:

int index = 2; int array1[anz] = { 0, 1, 2 }; int array2[anz] = { 0, 1, 2 }; int array3[anz] = { 0, 1, 2 }; int array4[anz] = { 0, 1, 2 }; if(array1[index] == 2) //dosomething 

new:

struct {     int type, conf, foo, bar; }; if(array1[index] == 2) //dosomething 

without touching array1[index] == 2, possible use define or else exact same behavior before old code?

with custom type, may do

struct mytype {     int& operator[](int index) const { return get(globalindexvariable)->subtype; } };  #define array mytype{} 

and then

array[globalindexvariable] 

will replaced by

mytype{}[globalindexvariable] 

which calls

get(globalindexvariable)->subtype; 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -