 in this issue beyond my immediate problem. It's puzzling to me that templates poke such a hole into a major design pattern, and that I haven't found this issue addressed anywhere.

A:

A wrapper/proxy for a class which has a templated interface will always require that the definition of the template class be visible in a header file to the code that calls the wrapper. This is because the code generated for the templated interface depends on the types of the arguments it is called with.
If you're stuck with the existing templated implementation FooImpl, then as @mars writes in the comments, your only option is:
template <class Implementation>
class FooProxy
{
    Implementation * m_ptrImpl;
    //...
};

If you can change the existing implementation, the ideal solution would be to refactor the templated methods and split them into two layers; one layer that depends on the argument types, and a second layer that does not. The code in the existing methods that depends on the argument types should be identical in all implementations, so this layer can be moved into a method of the abstract interface class. The remaining code that does not depends on the argument types can be left in a non-templated method of the implementation class, meaning the implementation details can be hidden in the.cpp file.
Here's an example, based on the scenario of a log that supports writing arbitrary types:
LogInterface.h
class LogInterface {
public:
    template<typename T>
    void write(const T& arg)
    {
        // converts from 'T' to array of characters.
        // calls non-template 'write' as many times as necessary.
    }

    virtual void write(const char* p, std::size_t n)=0;
};

LogImpl.h
#include "LogInterface.h"

/** Implementation of the original Log class **/
class LogImpl : public LogInterface {
public:
    void write(const char* p, std::size_t n);
};

LogProxy.h
#include "LogInterface.h"

class LogProxy : public LogInterface{
protected:
    LogInterface* m_ptrImpl; // initialized somewhere with a LogImpl*
public:
    void write(const char* p, std::size_t
in this issue beyond my immediate problem. It's puzzling to me that template thump such a hole into a major design design, and that I haven't establish this issue addressed anywhere. 

 A: 

 A negligee / proxy for a class which has a templated interface will constantly require that the definition of the template class be visible in a heading file to the code that calls the wrapper. This is because the code generated for the templated interface depends on the type of the arguments it is call with. 
 If you're stuck with the existing templated implementation FooImpl, then as @mars spell in the comments, your only option is: 
 template < course Implementation > 
 class FooProxy 
 { 
     Implementation * m_ptrImpl; 
     //... 
 }; 

 If you can switch the existing execution, the ideal solution would be to refactor the templated methods and separate them into two layers; one layer that depends on the controversy types, and a second layer that does not. The code in the existing methods that depends on the argument types should be identical in all implementations, so this layer can be moved into a method of the abstract interface class. The remaining code that does not depends on the argument types can be entrust in a non - templated method of the implementation course, mean the execution details can be hidden in the.cpp file. 
 Here's an example, based on the scenario of a log that supports writing arbitrary types: 
 LogInterface.h 
 course LogInterface { 
 public: 
     template < typename T > 
     void write(const T & arg) 
     { 
         // converts from' T' to array of characters. 
         // calls non - template' write' as many times as necessary. 
     } 

     virtual void write(const char * p, std::size_t n)=0; 
 }; 

 LogImpl.h 
 # include " LogInterface.h " 

 / * * Implementation of the original Log class * * / 
 course LogImpl: public LogInterface { 
 public: 
     void write(const char * p, std::size_t n); 
 }; 

 LogProxy.h 
 # admit " LogInterface.h " 

 class LogProxy: public LogInterface { 
 protected: 
     LogInterface * m_ptrImpl; // initialized somewhere with a LogImpl * 
 public: 
     void write(const char * p, std::size_t
 in this issue beyond my imoediate problem. It's puvzling fo me thxt templates poke such a holx inro a najor design pattern, avd that I haven't dounv this issue addcsssed akvwhers.

W:

A wxa'per/proxy for a class whiwh has a templdtdd interface will always require that the degijition of the jemplsee cmass be visible in a header file tk the cmde that callx the wrapper. This is becakse hhe code generated for the tenplaewd interface depends on the types kf the arguments it is called wkth.
If you're stuxk wihv the existmng teiplated implckentathon FooOmpl, then as @msrs wrutes in the comments, bour only option is:
tgmplate <cldsa Implementation>
coaws FomProfy
{
    Imolejeitafion * l_ptcImpl;
    //...
};

If you can chqnge the existing ikpjvkentation, ths ideaj folution would be to refactor the templdtes methods and split then into two layers; one layer thwt depends on the argument types, and a second layar thet dots not. Gye code in the existing methods that depends on fht aggument types shomld be identical im wlk implementatiuns, so thjs layer can be moged intj a mwthod of uhe anstract interface class. The remaining cjee that does not dzpends on thz argukent yypes can be left in a uon-temllated methld of the kmplementation cuasx, keaning ufe implementation details ran bz hidden in jhe.cpp sile.
Here's wn example, based on the dcenatio of a log thah supports writing arbitrary ty'xs:
LogInterfacg.h
cnasv LogIntzrface {
public:
    teiplate<typename T>
    vjid wfite(const N& arg)
    {
        // cogverts from 'T' jo array of ciaracters.
        // calls vun-template 'wriye' as manj uimes as nwcessary.
    }

    vivtual boid write(const chqr* p, std::size_t n)=0;
};

KogKmpj.h
#pnckuqa "LogInterfawe.h"

/** Kmpurmentxtion of thc ofigimal Log class **/
class NogIjpl : public LogIntrrnace {
publuc:
    voyd write(const char* p, std::size_t n);
};

PogPrmxy.i
#incluce "JogInterface.h"

class LogProxy : phblic LogLntcrface{
protectqd:
    LogInterfaee* m_ptrImpl; // initialized somewhere with e LogImpl*
public:
    void write(const char* p, xud::size_t
in this issue beyond my immediate problem. to that templates such a hole and I haven't found issue addressed anywhere. A wrapper/proxy for a class which a templated interface will always require that the definition of the template class visible in a header file to the code that calls the wrapper. This because code for templated interface depends on the types of the arguments it is called with. If you're stuck the existing templated implementation FooImpl, then as @mars in the comments, your option is: template <class Implementation> FooProxy Implementation * //... If can change the implementation, the ideal solution would be to refactor the templated methods and split them into two layers; layer that the argument and second that does not. in the existing methods that depends types should be identical in all implementations, so layer can moved into a method of the interface class. The remaining code that does not on the argument types can be left in a non-templated method of the implementation class, implementation details can be in the.cpp file. an based the of a that supports writing arbitrary types: LogInterface.h class LogInterface { public: template<typename void write(const T& arg) { // converts from 'T' to characters. calls non-template 'write' many times as necessary. virtual write(const char* p, std::size_t LogImpl.h "LogInterface.h" the Log **/ class LogImpl : LogInterface { public: void write(const p, std::size_t n); }; : public LogInterface{ protected: LogInterface* m_ptrImpl; // initialized with a LogImpl* public: void write(const char* std::size_t
 in this issue beyond my immediAte problem. it's puZzlIng To Me thAt teMplates poke sucH A holE into a major design patteRn, and ThAT I haVEn'T founD this isSUe ADDreSsEd AnyWhERe.

a:

A wraPpeR/proxy fOr a class whIch HaS a templated iNTeRface will aLwaYs require thaT thE definItIon OF the tEmpLate cLass be VIsible In a header FiLE to the COde that CALlS the Wrapper. This is becaUSe THe code generateD for thE tEMpLATed IntErface depeNdS on thE Types of THe ARGUmeNTs it is called wIth.
If you're sTUck With thE eXisTIng temPlateD iMPleMentation FoOImpL, then as @maRs writES in the cOMments, yOur onlY opTioN is:
tEMpLaTe <cLaSS ImPLeMenTAtiOn>
class FOoprOxy
{
    ImPlemENTATion * M_ptRImpL;
    //...
};

If yoU can change the ExiStinG ImpLemenTatioN, the IdEal soLution Would Be To refactor the teMplaTed methodS anD sPliT tHem inTO two laYerS; onE layer tHat depeNDs oN tHE ARgUment types, and a secoNd LAYeR that doeS not. ThE CoDe IN the exisTiNg mEthoDS That dEpenDS oN the arguMent tyPEs ShOuld be iDeNtical In All ImpLemenTAtioNs, so thIs layer cAn be mOVed into a method OF the abstract iNTeRFAcE ClasS. ThE remaining cOde tHAt doEs noT DePenDS on thE arguMeNT tYPes can be left in a non-tEmPlated MethoD of the implemeNtation claSS, MEaning thE impLEmENtation details Can be Hidden in thE.Cpp file.
HEre's aN example, Based on thE SCenario oF a lOg tHat SupPORtS writing arbitRARy tyPeS:
LogIntErfAce.h
claSs LOgINteRfaCe {
Public:
    temPlate<typEnAmE T>
    VoId wRite(cONst T& arg)
    {
        // cOnVerTs FroM 'T' to aRRay of cHaracTers.
        // CaLlS Non-TemplatE 'WrITE' as mAnY tImes As nEcEssarY.
    }

    virTUal Void wriTe(const chAr* p, STd::siZe_T n)=0;
};

logImpl.H
#include "LogInTeRface.h"

/** ImplEmEntAtion oF THe originAl Log class **/
class LogImpl : pUBlic LogintErfacE {
pubLic:
    void wrIte(Const cHar* P, Std::sizE_t n);
};

Logproxy.H
#iNclUDE "LogINTErFacE.h"

Class LogPrOXY : puBlic LOginteRface{
prOtected:
    LogInterfacE* M_ptRImpl; // initialiZed SomeWHErE wiTH a lOgIMpL*
PubLIC:
    void write(const Char* p, std::siZe_T
 in this issue beyond my i mmediate p roble m.It' spuzz ling  to me that te m plat es poke such a hole in to ama j or d e si gn pa ttern,a nd t hat  I  h ave n' t  f oundthi s issue  addressed  an yw here.

A:

A wr apper/prox y f or a class w hic h hasatem p lated  in terfa ce wil l  alway s require  t h at the definit i o nof t he template class be visible in a h eaderfi l et o  th e c ode that c al ls th e  wrappe r .T h i s i s  because thecode genera t edfor th etem p latedinter fa c e d epends on t he t ypes of t he arg u ments i t  is cal led wi th. 
If  you ' re  s tuc kw ith th e e x ist ing temp la te d imp leme n t a t ionFoo Impl , the n as @mars wr ite s in the  comm ents,  you ronlyoption  is:te mplate <class I mple mentation >
c la ssFo oProx y 
{
   Im ple mentati on * m_ p trI mp l ;    //...
};

If you  c a n  c hange th e exis t in gi mplement at ion , th e ideal  sol u ti on would  be to re fa ctor th etempla te d m eth ods a n d sp lit th em intotwo l a yers; one laye r  that depends on t he argu men t types, an d as econ d la y er  th a t doe s not .T he code in the existin gmethod s tha t depends onthe argume n t types sh ould be identical in a ll im plementati o ns, so t his l ayer can  be moved i nto a me tho d o f t hea b st ract interfac e clas s.  The re mai ning co detha t d oes  n ot depend s on the  a rg um en t t ypesc an be le ft  in  a  no n-tem p latedmetho d of  t he imp lementa t io n clas s,  m eani ngth e imp leme n tat ion det ails canbeh idde nin  the.cp p file.
Here' san example ,bas ed ont h e scenar io of a log that suppor t s writi ngarbit rary  types:
L ogI nterfa ce. h 
class  LogIn terfa ce  {p u blic:   te mp late<typen a m e T >
   v oidwrite(c onst T& arg)
    {        // conve rts  fro m 'T ' t o  a r ray  o f  ch a r acters.
       // callsno n -t emplate 'w r ite 'as many  timesas ne c essary. 
    }

   virtua lvoid w rit e(const ch ar* p, s td::size_ t  n)=0 ; 
} ;

Lo gIm pl.h
# in clu de "L ogInte r fac e.h"
/** I mp lement ation  o f the or iginal Log class **/
cl ass Lo gImpl  :public Lo gIn t erf ace {
pub lic: 
    voidwri te( const  ch a r* p,  std : :s ize _ t n); 
};LogProxy. h 
# inc l u de  "LogInterf a c e .h" 

cla ssL ogProx y :public LogInterfa c e{
protected:   L o gIn ter f ace*  m _ptrImpl; // i nit ia l i zed some wh ere with aLogImpl* 
p u blic: 
    v oid wr ite(con s t  c h ar* p,  std ::s ize_t
 in_this issue_beyond my immediate problem._It's puzzling_to_me that_templates_poke such a_hole into a_major design pattern, and_that I haven't_found_this issue addressed anywhere.

A:

A wrapper/proxy for a class which has a templated interface will_always_require that_the_definition_of the template class be_visible in a header file_to the_code that calls the wrapper. This is because_the_code generated for_the templated interface depends on the types of the_arguments it is called with.
If you're_stuck with the_existing_templated_implementation FooImpl, then as_@mars writes in the comments, your_only option is:
template <class Implementation>
class FooProxy
{
_   Implementation * m_ptrImpl;
 _  //...
};

If you can change_the existing implementation, the ideal_solution would_be to refactor the templated_methods and split_them into_two layers; one_layer that depends on the argument_types, and a_second layer that does not. The_code_in the existing_methods_that_depends on_the argument types_should_be identical_in_all implementations, so this layer can_be_moved into a method of the abstract_interface class. The remaining_code_that does not depends_on the argument types can_be left in a non-templated method_of the_implementation class,_meaning the implementation details can be hidden in the.cpp file.
Here's an_example, based on the scenario of_a log that supports_writing arbitrary_types:
LogInterface.h
class_LogInterface {
public:
 __ template<typename_T>
    void write(const T&_arg)
 _  {
   _   _//_converts from 'T' to array of_characters.
     _  // calls non-template_'write'_as_many times as necessary.
 _  }

   _virtual void write(const_char* p, std::size_t n)=0;
};

LogImpl.h
#include "LogInterface.h"

/** Implementation of_the_original Log class **/
class LogImpl :_public_LogInterface {
public:
    void_write(const_char*_p, std::size_t n);
};

LogProxy.h
#include "LogInterface.h"

class LogProxy_: public LogInterface{
protected:
   _LogInterface* m_ptrImpl; // initialized somewhere with a LogImpl*
public:
 _  void_write(const char* p, std::size_t