Can I put one type in a template as default value or null in c++ -
i want develop class this:
template <typename t> class { public void dosomething() { if(t !=null) { // work t.report("i here"); // more work. } } } and use similar this:
class b { public: void report(std::string msg) { std::cout<<msg<<std::endl; } } main() { a<b> reporttostd; a<null> donotreport; } so if not defining class report, object not reporting back. idea make fast can pass parameter aach object saying report or not. don't want have empty class messy.
the best way explicitly instantiate template class. so:
template<> class a<null_t> { void dosomething() { } }; that way when class created template wouldn't anything.
Comments
Post a Comment