I try to (basically) make a Setter method for a std::vector (its D3D10 rendering)
void GraphicsClass::BeginFrame(vector<LightClass> const &vlights)
{
lights = vlights;
where lights is a private member of GraphicsClass, declaration:
vector<LightClass> lights;
Now, the properties of the array get copied; but the elements lights[0], lights[1]
etc contain garbage. I checked this using the Visual Studio debugger.
I could obviously work around by using
void GraphicsClass::BeginFrame(vector<LightClass> const &vlights) {
int size = vlights.size();
int i;
lights.resize(size);
for (i = 0; i < size; i++)
lights[i] = vlights[i];
But I don't like that I don't understand this topic, and this code seems a good bit slower.
Thanks in advance for answers!
LightClass as requested:
class LightClass
{
public:
LightClass(void);
~LightClass(void);
void SetDiffuseColor(float, float, float, float);
void SetDirection(float, float, float);
D3DXVECTOR4 GetDiffuseColor();
D3DXVECTOR3 GetDirection();
private:
D3DXVECTOR4 m_diffuseColor;
D3DXVECTOR3 m_direction;
};
both the constructor and the destructor are empty which is a mistake (I copied this from classes which I only create pointers to. like Type *thing. I'm new to OOP)
I will probably change the vector to vector though.
You need to have implemented a copy constructor for LightClass
, not just operator=
(as in your workaround).