C++ setGender method reverts to default values -


i've written code bits below. have constructor takes 5 arguments. unfortunately, setgender method spits out default 'm' instances of class rather setting gender specified parameter. doing incorrectly? advice appreciated. thank you.

dateprofile::dateprofile(char gdr,     char searchgdr, int romancescale, int financescale, string thename)  bool dateprofile::setgender(char gdr) {    if (gdr != 'm' || gdr != 'f')       return false;    gender = gdr;    return true; } 

if (gdr != 'm' || gdr != 'f') always true, irrespective of input. if you're passing 'm', second part of expression true. if you're passing else, first part of expression becomes true.

what meant write if (gdr != 'm' && gdr != 'f') instead.

increasing warning level of compiler may have helped spot error. compilers warn expressions evaluating single value, or @ least unreachable code following it.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -