How to force use of curiously recurring template pattern in C++ -


i have following base template class.

template<typename t> class base {   public:     void do_something() {     } }; 

it intended used curiously recurring template pattern. should inherited class b : public base<b>. must not inherited class b : public base<someoneelse>. want statically enforce requirement. if uses wrong, expect error in compiling phase.

what i'm doing putting static_cast<t const&>(*this) in do_something(). way class inheriting template or inherits class provided template parameter. sorry confusing expression. in plain english, requires b or inherits someoneelse in class b : public base<someoneelse>.

i don't know if it's optimal way achieve this. looks gross me.

however want more. want ensure b someoneelse itself. how can that?

make constructor (or destructor) of base private, , make t friend. way thing can construct/destruct base<t> t.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -