What I understand that you're wanting to do is to declare a function inside of a struct that is available as a member of this struct to perform operations on member variables (specifically an array of three elements). I'm guessing that in reference to C++, you are thinking of the functionality within a class to define a function that will use member variables native to each instance of the class as in the example.
class Foo {
int x;
int addThree( ) {
x += 3;
}
}
If I understand your question correctly, the simple answer is no. Since LabWindows/CVI is based on the C programming language, the lack of object-oriented class structure in the C language inhibits the use of a function in a struct. Please note that, similar to C++, if you define a struct instead of a class, you cannot define functions within it either.
That being said, it sounds like you are just wanting to perform an operation on the same type of struct. Outside of the struct, you CAN define a function that performs an operation on struct members. In the following example, you can see how the function will perform an operation on a class member.
struct V3 {
double Vec[3];
} ;
double Average (struct V3 foo) {
int i;
double sum = 0;
for (i=0; i<sizeof(foo.Vec)/sizeof(*foo.Vec); i++) {
DebugPrintf("%d\n",i);
sum += foo.Vec[i];
}
return (sum/i);
}
If I have misunderstood your question, please let me know.
Hope this helps!
Andy McRorie
Applications Engineer
National Instruments
Thanks,
Andy McRorie
NI R&D