class - C++ warning [-Wunused-value] -


i have problem c++ code, there no errors warning preventing code work should. multiply screen size percentage , print it.

this in .h file:

smartwatch* multiply(smartwatch* second, double percentage); 

and in .cpp file:

smartwatch* smartwatch::multiply(smartwatch* second, double percentage){ second->getscreen_size() * percentage; return second; } 

and in main:

smartwatch *multiplied = &watch[0]; multiplied = multiplied ->multiply(&watch[1], 0.23); multiplied->print(); 

i warning:

smartwatch.cpp:69:31: warning: expression result unused [-wunused-value] second->getscreen_size() * percentage;

i new @ this, don't know doing wrong.

you don't store value of multiplication in multiply method anywhere. compiler warning because line of code second->getscreen_size() * percentage; doesn't store result or change value. result of multiplication discarded.

to fix warning, should store result smartwatch* second pointer somewhere. i'm not sure class design looks like, like:

second->setscreen_size(second->getscreen_size() * percentage); 

to remove warning , accomplish method you've written.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -