1. Array and classes problem

Sorry tabstop, I completed the question and made it better.
-----------------------------------------------------------

I have a class like such:

Code:
```class Sphere
{
public:
Sphere(){};
~Sphere() {};
Sphere(string m_name) : name(m_name) {};
void SetValues(float m_posx, float m_posy, float m_posz,
float m_sclx, float m_scly, float m_sclz,
float m_r, float m_g, float m_b,
float m_Ka, float m_Kd, float m_Ks, float m_Kr,
float m_n)
{
Ka = m_Ka; Kd = m_Kd; Ks = m_Ks; Kr = m_Kr;
n = m_n;
center.x  =  0.00; center.y = 0.00; center.z = 0.00;
sphereColor.r = m_r;
sphereColor.g = m_g;
sphereColor.b = m_b;
SetTranformMatrix(m_posx, m_posy, m_posz,
m_sclx, m_scly, m_sclz);
};

//set the transfor matrix
void SetTranformMatrix( float posx, float  posy, float posz,
float sclx, float  scly, float sclz)
{
Trans[0][0] = sclx;
Trans[0][1] = 0;
Trans[0][2] = 0;
Trans[0][3] = posx;
Trans[1][0] = 0;
Trans[1][1] = scly;
Trans[1][2] = 0;
Trans[1][3] = posy;
Trans[2][0] = 0;
Trans[2][1] = 0;
Trans[2][2] = sclz;
Trans[2][3] = posz;
Trans[3][0] = 0;
Trans[3][1] = 0;
Trans[3][2] = 0;
Trans[3][3] = 1;
};

//should return the depth at which the the ray has intersected otherwise return -1;
double intersect(ray &m_ray)
{

double T_Inverse[4][4];
invert_matrix(Trans, T_Inverse);

//buncha lines here
}

std::string name;
double Trans[4][4];	//transition matrix
color sphereColor;

private:
point center;
float Ka, Kd, Ks, Kr;
float n;	//specular

};```
and a function like such:
Code:
```float compute_closest_intersection(ray &m_ray, Sphere * m_spheres)
{
float intersect = -1;
float temp_intersect;
for(int i=0; i < 3; i++)
{
temp_intersect = m_spheres[i].intersect(m_ray); //HERE HERE HERE HERE
intersect = (temp_intersect >= intersect) ?  temp_intersect : intersect;
}
return intersect;
}```
and in main I have
Code:
```Sphere inputSphere[5];
float testiii = compute_closest_intersection(Thru_Pixel,InputSphere);```
- and the problem: Trans[][] doesn't have values,
(where it was initialized in the SetTranformMatrix() function)
when the intersect is called from compute_closest_intersection function.

in a nutshell

Why doesn't Trans[][] keep the values assigned to it in the SetTranformMatrix() function.

-Thank you

2. Who knows? It's not as through "set int Transform[4][4] to be constant" means anything.
And by the way, there already is a vector in C++.... (Thank goodness for namespaces, right?)

3. Does "constant" mean you add the "const" keyword to it or something else?

4. Apparently you can't make it constant: there would be no way to initialize values in it and you can't change them later. Hence it would be useless.

You could, perhaps, place the array inside a struct/class, so you can initialize it with the result of a function that returns this array object.

5. Originally Posted by anon
Apparently you can't make it constant: there would be no way to initialize values in it and you can't change them later. Hence it would be useless.
Huh? Of course there's a way to initialize constant values in a class...

6. Originally Posted by Elysia
Of course there's a way to initialize constant values in a class
The member variable is an array, and the normal initializer syntax for arrays cannot be used in initialisation lists, if I remember correctly.

7. Each Sphere has its own copy of Trans; once you call SetValues on that Sphere, then it will have values in the Trans matrix. T_Inverse will go away after the function call ends.

8. Originally Posted by laserlight
The member variable is an array, and the normal initializer syntax for arrays cannot be used in initialisation lists, if I remember correctly.
Oops, you're right. Oversight?
But then again, perhaps std::vector or std::tr1::array would work.

9. Ok , but why wouldn't Trans[][] hold the values assigned to it in the SetTransformMatrix()?

10. Originally Posted by armen
Ok , but why wouldn't Trans[][] hold the values assigned to it in the SetTransformMatrix()?
It will. Why do you think it won't?

Edit: I should be more specific: I've been assuming, despite the code that you've posted, that you are in fact calling SetTransformMatrix at some point (at least via SetValues).