Friday, 15 March 2013

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


I have a problem with my C ++ code, there is no error, but only the warning that my code will work Prevents from I want to multiply the screen size by percentage and want to do it with print.

This is in my .h file:

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

And it's mine. CPP file contains:

  smartwatch * smartwatch :: multiplication (smartwach * second, double cent) {sec- gt; GetScreen_size () * percent; Second return; }  

And it's in the main:

  smartwatch * times = & amp; Clock [0]; Multiplication = multiplication - & gt; Multiply (& amp; see [1], 0.23); Multiplied- & gt; Print ();  

I get this warning:

smartwatch.cpp: 69: 31: WARNING: Expression unused [-vide-value] second-> getScreen_size () * percent ;

I'm new to this, so I do not know what I'm doing wrong

You do not actually store the value of the product in the multiply method. Anywhere the compiler is warning you because the code seconds-> getScreen_size () * percent; The line result of does not look or changes the value, the result of multiplication will be rejected.

To correct the alert, you should put the result back from somewhere in the SmartWatch * second indicator. I'm not sure how your class design looks, but you can do something like this:

  seconds-> set-screen_size (seconds-> getScreen_size () * percent);  

To get rid of the warning and then actually get something with the method you wrote.


No comments:

Post a Comment