Nov 8, 2010 at 1:38pm UTC
Hi friends,
Define a type Vec4 as a vector of four floats.saying it now says the following.
class Vec4{
vector<float> f1;
vector<float> f2;
vector<float> f2;
vector<float> f3;
};
I understand that if I do wrong.
Last edited on Nov 8, 2010 at 1:42pm UTC
Nov 8, 2010 at 2:00pm UTC
Not sure I understand what you're saying.
Here you've defined a class with four vectors of floats as member vairables. I think if you need it to be four floats, then an array is better for you than a vector? Vectors are meant to be dynamically sized.
Nov 8, 2010 at 2:07pm UTC
something like this?
class Vec4{
vector<float> f(4);
public:
Vec4()
{
}
};
Last edited on Nov 8, 2010 at 2:10pm UTC
Nov 8, 2010 at 2:36pm UTC
or something like that?
typedef float float4[4];
class Vec4{
vector<float4> fval;
public:
Vec4()
{
}
};
Nov 8, 2010 at 2:49pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <vector>
using namespace std;
struct FourFloats
{
float data[4];
FourFloats(float a, float b, float c, float d)
{
data[0]=a;
data[1]=b;
data[2]=c;
data[3]=d;
}
};
int main()
{
vector<FourFloats> my_ff_vec;
my_ff_vec.push_back(FourFloats(1.0f, 2.0f, 3.0f, 4.0f));
my_ff_vec.push_back(FourFloats(1.1f, 2.2f, 3.3f, 4.4f));
cout << my_ff_vec[0].data[1] << endl;
cout << my_ff_vec[1].data[2] << endl;
return 0;
}
Or...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <iostream>
#include <vector>
using namespace std;
template <unsigned int N, class T>
struct NTs
{
T data[N];
};
int main()
{
vector<NTs<4,float > > my_ff_vec;
NTs<4,float > temp;
int i;
for (i=0; i<4; i++) temp.data[i]=i+1;
my_ff_vec.push_back(temp);
for (i=0; i<4; i++) temp.data[i]=i+1+0.1f*(i+1);
my_ff_vec.push_back(temp);
cout << my_ff_vec[0].data[1] << endl;
cout << my_ff_vec[1].data[2] << endl;
return 0;
}
Last edited on Nov 8, 2010 at 2:55pm UTC
Nov 8, 2010 at 3:01pm UTC
I think yes, like this one,