سؤال

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