boost::static_pointer_cast problem.
I am getting the following error trying to use boost::static_pointer_cast with shared_ptrs:
Error 19 error C2440: 'static_cast' : cannot convert from
'fusion::scene_graph::transform_graph::Light *const ' to
'fusion::scene_graph::transform_graph::Transform *'
c:\programming\lib\boost_1_34_0\boost\shared_ptr.hpp 199
The code that generates the error:
void Transform::DirtyTransformsVisitor::visitTransform(const TransformPtr &transform)
{
transform->dirtyTransform();
}
void Transform::DirtyTransformsVisitor::visitLight(const LightPtr &light)
{
visitTransform(boost::static_pointer_cast<Transform>(light));
}
The declarations:
class Transform; typedef boost::shared_ptr<Transform> TransformPtr;
class Drawable; typedef boost::shared_ptr<Drawable> DrawablePtr;
class Light; typedef boost::shared_ptr<Light> LightPtr;
class DirtyTransformsVisitor : public TransformVisitor
{
public:
void visitTransform(const TransformPtr &transform);
void visitLight(const LightPtr &light);
};
Has anyone got any idea why the pointer in my Light is const when the static_pointer_cast template is expanded?! I don't see why I should need to use a const_cast in this context, as non of the involved functions are const.
Thanks!
[1427 byte] By [
billw] at [2007-11-20 8:26:17]

# 1 Re: boost::static_pointer_cast problem.
Given the code you posted, I am more concerned if there is a valid relation ship between a "Light" and a "Transform"... If it NOT shown by the posted (partial code).
When posting code with these types of problems it is ALWAYS a good idea to reduce your environment to the absolute minimum that can reproduce the error. This allows someone to copy/paste your code into an empty .cpp file compile it and get the same error...
If this is not followed then it is highly likely that time will be wasted (or not even bothered with), since it really just becomes a guessing game.
Also not that the error message is
Light * const
and not
Light const *
So they does your target method NEED to change the address that the pointer is pointing to in the first place?? :confused: :confused: :confused:
# 2 Re: boost::static_pointer_cast problem.
Yes you are right. I tried to recreate the problem in a single project with just the bare bones, and it worked fine. I went back and changed my code back to how it was when the problem was occuring and now it doesn't, so it must have been something else.
Sorry to waste your time!
billw at 2007-11-10 22:32:00 >
