문제

I have const correctness issue with QList.

I have a method getValue whose signature i cannot change returning const double and here

double vs = MinInput->getValue(0, 0);

vs is const.

I would like to build QList with results from this method and i get error C3892.

Since my list is a QList, cannot add const double (?)

Code is like that

    QList<double> minmax;
    for (int i = 0; i < 2*(3+othercutoffs_var_len) ; i++  )
        minmax.append( 0.0 );


    QSP< const VarInterface<double> > MinInput = ctx.getInputVar<double>(ctx.input(Id::fromString(QL1s("Min")))[0] );
    const double vs = MinInput->getValue(0, 0);
    minmax.at(0) = vs;

and this very last line of code is getting me into trouble. (other errors when filling the list with other such const doubles)

signature for getValue is like that

const TYPE & VarData<TYPE>::getValue( uint r, uint c ) const
도움이 되었습니까?

해결책

I guess the correct code would be:

minmax[0] = vs;

Update:

QList::at returns const reference, which cannot be modified.

다른 팁

QList::at(int i) is a getter function. It returns a const reference, and you cannot assign anything to it.

Use QList::operator[](int i) or QList::replace(int i, const & T value) to set the value at position i.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top