"Vec4 as a vector of four floats"

Hello,
I want to Define a type Vec4 as a vector of four floats

1
2
3
struct floatt{
 float f[4];
};
how should I begin

Is it that correct

1
2
3
class Vec4{
 floatt fval;
};


Is it that correct

1
2
3
class Vec4{
vector<floatt> fval;
};


Last edited on
Hi frix,
if you want to define a new type, you can use the "typedef" instruction. Secondly, if the new type will always hold 4 floats, you can do with an array. "vector" is useful for dynamic arrays, that is arrays whose size can change.

 
typedef float vec4[4];


then you use the type like this:
 
vec4 myVec4;

What typedef statement
Do you think a reasonable answer?
for my question?
The simplest, sanest solution would be:

1
2
3
struct Vec4 {
    float w, x, y, z;
};

Just add a default constructor and one that takes four parameters.
firix,
given how you formulated the question, yes I do think that my answer is pertinent. Anyway if you don't like it you are free to discard it. I won't be bothered a bit.

On a side note, you might want to express yourself politely if you want people to reply to your posts in the future.
@obice: a typedef, despite what it looks like, doesn't really define a new type; it simply creates an alias for an existing type. When someone say they want to define a type they mean class or struct.
@obice

typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.

please

you see my question again ?
Last edited on
Topic archived. No new replies allowed.