c++ - returning bool from member variable pointer -


so i'm working code looks this:

class someclass : public somebaseclass {     somepointertoclass * p;   public:     someclass(somepointertoclass* p = null) : p(p) {};     void start(somepointertoclass* sp) {         p = sp;     }     bool hasstarted() {         return p;     } } 

i simplified stuff make short code example, think returning bool member variable pointer bit of codesmell. should change or form of c++ convention?

hasstarted() fine: in c++, pointer automatically converted bool on zero/not-zero basis.

some people prefer write return (p != nullptr) or return static_cast<bool>(p) instead, in order explicit intent, i'm not terribly fussy in cases this.

however, behaviour implementation-defined in c, not rely on there!


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -