This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example:
[CODE=javascript]var myInstance:myCl ass = new myClass();
myInstance.memb er_0 = memberValue_0; // absolute notation
myInstance[0] = memberValue_0; // relative notation
myInstance["member_0"] = memberValue_0; // nominal notation[/CODE]
You can initialize a struct in C/C++ like you would an array, as with the following code:
[CODE=c]struct myClass {
int member_0;
int member_1;
int member_2;
}
myClass myInstance = {memberValue_0, memberValue_1, memberValue_2};[/CODE]
So my question is: Is it possible to access the members of a struct using the array syntax in the same manner as in the following?:
[CODE=c]struct myClass {
int member_0;
int member_1;
int member_2;
} myInstance;
myInstance.memb er_0 = memberValue_0; // proper syntax
myInstance[0] = memberValue_0; // legal?
myInstance["member_0"] = memberValue_0; // legal?[/CODE]
This question is purely academic and serves only my personal curiosity. I haven't worked in C or C++ for over a decade now, and I do not have access to a compiler to verify my question.
[CODE=javascript]var myInstance:myCl ass = new myClass();
myInstance.memb er_0 = memberValue_0; // absolute notation
myInstance[0] = memberValue_0; // relative notation
myInstance["member_0"] = memberValue_0; // nominal notation[/CODE]
You can initialize a struct in C/C++ like you would an array, as with the following code:
[CODE=c]struct myClass {
int member_0;
int member_1;
int member_2;
}
myClass myInstance = {memberValue_0, memberValue_1, memberValue_2};[/CODE]
So my question is: Is it possible to access the members of a struct using the array syntax in the same manner as in the following?:
[CODE=c]struct myClass {
int member_0;
int member_1;
int member_2;
} myInstance;
myInstance.memb er_0 = memberValue_0; // proper syntax
myInstance[0] = memberValue_0; // legal?
myInstance["member_0"] = memberValue_0; // legal?[/CODE]
This question is purely academic and serves only my personal curiosity. I haven't worked in C or C++ for over a decade now, and I do not have access to a compiler to verify my question.
Comment