Const Discards Qualifers: C++
Posted
by
user991673
on Stack Overflow
See other posts from Stack Overflow
or by user991673
Published on 2011-11-12T01:26:24Z
Indexed on
2011/11/12
1:51 UTC
Read the original article
Hit count: 162
I'm using OpenGL to render camera perspectives, and a one point in my code I'm trying to take the direction of the light (shown here as type "Vector4") and multiply it by a matrix of type "Matrix4x4" that represents the Modelview transformation (sorry if this is not making any sense, this is for a school project, as such I'm still learning about this stuff) Anyway, my code goes as follows...
Vector4 lightDirection = data->dir * follow->getModelviewMatrix().getInverse().getTranspose();
data->dir = lightDirection;
setLight(*data);
this give me the following error:
passing 'const vec4<double>' as 'this' argument of 'vec4<T>& vec4<T>::operator=(const vec4<T>&)[with T = double]' discards qualifiers
Again, much of this code is prewritten for the class (namely the vector and matrix types) but if someone could just help me decipher what the error means it would be much appreciated! I can give more information as needed.
I figured 'data' or 'data->dir' were const, however I can find no mention of either of them to be. 'dir' is of type SceneLightData, and when its added on I'm doing this:
void Scene::addLight(const SceneLightData &sceneLight)
{
SceneLightData light = sceneLight;
m_lights.push_back(&light);
}
The error occurs on this line:
data->dir = lightDirection;
EDIT
problem solved. thanks everyone! solution:
void Scene::addLight(const SceneLightData &sceneLight)
{
SceneLightData* light = new SceneLightData;
*light = sceneLight;
m_lights.push_back(light);
}
and
SceneLightData* data = m_lights[i];
data->dir = data->dir * follow->getModelviewMatrix().getInverse().getTranspose();
setLight(*data);
© Stack Overflow or respective owner