what c++ inline explicit constructor is good for? -
this question has answer here:
- what explicit keyword mean? 10 answers
i see constructor writing inline explicit. example:
protected : inline explicit singleton() { ccassert(singleton::instance_ == 0, "error singleton::instance_ == 0."); singleton::instance_ = static_cast<t*>(this); } inline ~singleton() { singleton::instance_ = 0; }
for inline explicit ?
inline
necessary if define function in header, not in class definition. allows function defined in multiple translation units (i.e. when including header multiple source files). purpose allow compiler inline calls function - many compilers require definition available within translation unit in order that.
in case it's pointless: functions defined within class definition implicitly inline.
explicit
means constructor can't used implicit type conversions. historically, made sense single-argument constructors; think these days can used prevent brace-initialisation.
in case, it's pointless: default constructors aren't used implicit conversions.
for inline explicit ?
here, both give useful code smells - author values verbiage , excessive structure on clarity. further evidenced use of singleton anti-pattern - tread in code.
Comments
Post a Comment