Reputation: 16900
I need to do calculations based on a variable anmount of data, each item in the data containing 3 values. I could use an array, struct or a class to represent one of the items.
Is there any difference in speed or do they behave all the same way?
// #1: Only arrays
typedef int triple[3];
// #2: Using a struct
struct triple {
int a;
int b;
int c;
};
// #3: Using a class
class triple {
public:
int a;
int b;
int c;
};
Upvotes: 2
Views: 748
Reputation: 143279
There should be definitely no difference between struct
and class
with public:
at the beginning and I suspect there will be no difference with array as well. Not at run time.
Upvotes: 1
Reputation: 14083
Structs and classes are the same as far as that goes. As long as you use a constant index, all the math is done at compile time, so it shouldn't make any difference.
Upvotes: 7