templates - Is this code from old Alexandrescu's C++ book valid? -


i reading old alexandrescu's book c++ templates , came across following code snippet explained abstractfactory pattern implementation (chapter 9.3). here is:

template <class, class, class> class genlinearhierachy; template <class, class> class opnewfactoryunit; template <class> class reverse;  //definitions  template <     class abstractfact,     template <class, class> class creator = opnewfactoryunit     class tlist = typename abstractfact::productlist > class concretefactory : public genlinearhierarchy< typename tl::reverse<tlist>::result, creator, abstractfact> //here. { public:     typedef typename abstractfact::productlist productlist;     typedef tlist concreteproductlist; }; 

i don't why code valid. didn't defined tl anywhere in snippet.

no, code you've posted not correct.

there's few typos aren't relevant i'll mention them. may in book or maybe made when posted this. don't have book can't check

  • genlinearhierachy should genlinearhierarchy
  • comma missing @ end of opnewfactoryunit before template parameter

now out of way, no snippet not declare tl namespace or template <class> class reverse; inside namespace. declare template <class> class reverse; outside tl namespace, might error in book assuming that's entire snippet , there's no reason assume additional headers required.

the declaration related loki::tl::reverse< nulltype > declared in typelist.h of loki library.

third thing find confusing template parameter template <class, class> class creator = opnewfactoryunit passed second type parameter template <class, class, class> class genlinearhierachy though creator not type template! seems genlinearhierarchy intended template <class, template <class, class> class, class> class genlinearhierarchy;. match loki::genlinearhierarchy

with changes (fix typos, remove tl namespace, change type of genlinearhierarchy), code parses correctly.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -