What is wrong with my syntax in this 1-line bit of code (pointers and links and markup oh my)?

The code I came across is the line:

result.addElement(&(*(setArray[i]) + *(rhs.setArray[j])));

The + operator in my class is overloaded in this way (there are many overloads that can fit into this set, but they all have a similar heading):

const Rational Rational::operator+(const Rational &rhs) const

Multiplying in the above code are arrays of pointers, but the + operator needs links, which can be a problem.

AddElement, the result method, has this header:

bool Set::addElement(Multinumber* newElement)

The Multinumber * header contains the Rational parent class mentioned above. I don't think any particular code matters. I am sure this is a syntax issue.

My compiler error:

68: error: invalid conversion from 'const Multinumber*' to 'Multinumber*'

Thank you for your help!

+3
4

, , const typecast -.

- , . , , addElement, , , , ( ), ( , re ).

-

bool Set::addElement(Multinumber newElement) //pass the Multinumber by value

addElement :

result.addElement(*setArray[i] + *rhs.setArray[j]);

, , * , [], setArray[i] setArray[i] . , .


, , , setArray - Set, Multinumber** Multinumber*,

result.addElement(setArray[i] + rhs.setArray[j]);


EDIT Ugggh. . new Rational -, , , :

result.addElement( new Rational(*setArray[i] + *rhs.setArray[j]) );

Set::addElement.


, ( ).

0

const

bool Set::addElement(Multinumber* newElement) Set::addElement(const Multinumber* newElement)

+2

operator + const. , addElement , . , addElement , Multinumber , operator + .

, . .

, , addElement const , EVERYWHERE.

+1

, addElement -const, + const.

,

addElement ((Multinumber *) & (* (setArray [i]) + * (rhs.setArray [j])));

, , addElement. , API , . .

, .

+1

Source: https://habr.com/ru/post/1777822/


All Articles