Error correction

hi,
please help me correcting this error or at least suggest some.
error C3892:
'sofa::helper::vector<T>::operator []' : you cannot assign to a
variable that is const
1> with
1> [
1> T=sofa::defaulttype::Vec<1,double>
1> ]


The error is for the commented line below:


if(_mstate->getSize()>5)
{
(*_mstate->getX0())[0].x() = thetaX; //error here
(*_mstate->getX0())[1].x() = thetaZ;
(*_mstate->getX0())[2].x() = state.toolRoll;
(*_mstate->getX0())[3].x() = state.toolDepth*Scale.getValue();
(*_mstate->getX0())[4].x() =state.opening;
(*_mstate->getX0())[5].x() =state.opening;
}

So far what I can understand is that *_mstate->getX0 is returning a constant type and the line is trying to assign to a constant.I don't know if I am totally correct.But I am looking for an answer which need not to modify any of the operator related function or getX0 function.
If not possible please at least say it to me.

thanks
Last edited on
Without knowing what type your things are, we can't help.
closed account (yUq2Nwbp)
what returns getX0() ??
Sorry for insufficient information

virtual const VecCoord* getX0() const = 0;

this is the function prototype.I guess it'll help.
*_mstate is a pointer to VecCoord type which is nearly same as a vector.

and thetax is a double.
Last edited on
closed account (yUq2Nwbp)
i think error is here (*_mstate->getX0())[0]........as i understood you have abstract class and other classes which inherit from your abstract class.....(*_mstate->getX0())[0] is object but your base class is abstract so you can't create object.....try refer to x() like this pointer->x().......
Thanks for your reply but it doesnt help.

I think I should do some more research on this.
May be then I will be able to make it more clear to you all.

Last edited on
You could start by showing what the type of _mstate is.
Now I think I can explain my problem better

if(_mstate->getSize()>5)
{
(*_mstate->getX0())[0].x() = thetaX; //error here
(*_mstate->getX0())[1].x() = thetaZ;
(*_mstate->getX0())[2].x() = state.toolRoll;
(*_mstate->getX0())[3].x() = state.toolDepth*Scale.getValue();
(*_mstate->getX0())[4].x() =state.opening;
(*_mstate->getX0())[5].x() =state.opening;
}


////////////////////////////////////////////////////////////////////////////////

Here _mstate is a pointer to a BaseMechanical state object
core::componentmodel::behavior::BaseMechanicalState* _mstate;


_mstate has been typecasted to MechanicalState pointer (srry if some terms are wrong)
this->_mstate = dynamic_cast<core::behavior::MechanicalState<Vec1dTypes>*> (context->getMechanicalState());


MechanicalState is inherited from BaseMechanicalState class
class MechanicalState : public BaseMechanicalState


BaseMechanical state contains VecCoord type members which which contains a set of vectors.

getX0 is defined in MechanicalState class
virtual VecCoord* getX0() = 0; 
virtual VecCoord* getX0() = 0; 


the operator is defined as follows:
const_reference operator[](size_type n) const
reference operator[](size_type n) 


// here I am not getting it
x() is defined as
const real& sofa::defaulttype::Vec< N, real >::x( )  const



And the error message is
error C3892: 'sofa::helper::vector<T>::operator []' : you cannot assign to a variable that is const
1>        with
1>        [
1>            T=sofa::defaulttype::Vec<1,double>
1>        ]


Now I think I am clear enough.I tried to do lot of things but I am stuck here.
Could you please help?









Last edited on
closed account (yUq2Nwbp)
does your BaseMechanicalState class inherit from VecCoord??
No, the parent of BaseMechanicalState contain VecCoord type member variables.
closed account (yUq2Nwbp)
statesman i can't understand what happens but i can give advance to you.......comment all the parts of your program that you think work correct.....it would facilitate your work to find error...
Topic archived. No new replies allowed.