visual c++ - C++ How can I use template collections of template objects with inheritance? -


okay... first off i'm going explain architecture i'm after looks like. statmgr

i trying implement stats manager stats objects. stats manager designed using templates (see declaration in pic).the statmgr holds map (not stl) maps string implementation smart pointer (which template), aref. specific sub-classes of statmgr statically declare template class of parent statmgr on construction (see lstatmgr , rstatmgr), , not template classes.
allows me things like:

lstatmgr mylstatmgr(10); if(mylstatmgr.remove(ackey))    cout << "remove good" << endl; //no need delete :) 

or

aref<lstat> olstat = null; mylstatmgr.getnextstat(ackey,olstat); if(olstat != null)   olstat->dosomethinglstatlike(); 

however before mister linker , madam compiler decided join forces , thwart attempts @ progress (i still have test functionality , memory use!).
stands have following error , warning per stat class:

.\statsmgr.cpp(740) : warning c4661: 'void statsmgr::vprint()' : no suitable definition provided explicit template instantiation request
.\statsmgr.cpp(740) : warning c4661: 'void statsmgr::vprint()' : no suitable definition provided explicit template instantiation request
.\statsmgr.cpp(104) : error c2084: function 'statsmgr::statsmgr(const enum docollect,const int)' has body
.\statsmgr.cpp(104) : error c2084: function 'statsmgr::statsmgr(const enum docollect,const int)' has body

now regarding warnings :: @ line 740 there delarations so:

template class statsmgr<lstat>; template class statsmgr<rstat>; 

i added because if don't end mess of linker errors (see them below). there declarations , implementations of vprint() in of stat subclasses!

regarding errors: base class "statsmgr" has defined cotr, subclasses (lstatmgr & rstatmgr). why inheritance not sort out? explicit template instances @ end of cpp cannot understand going on.
below statsmgr.cpp

template<class type> statsmgr<type>::statsmgr(const docollect eoption, const int nlistsize) :     omymap(whashstring, nlistsize), omymapiter(ostatslist) {     m_ecollectionoption = eoption; } 

below lstatmgr.cpp

lstatmgr::lstatmgr(const docollect eoption, const int nlistsize) : statsmgr<lstat> (eoption, nlistsize) { } 

i tried substituting

class lstatmgr; class rstatmgr; 

for template declarations , gets passed compile errors linker cannot find non-overridden functions. example if have function in statmgr called "getnextstat()" , override in rstatmgr not in lstatmgr, linker complains that. why inheritance not covering situation?



it makes me sad. may have fall composition (which should preferred, not in situation).
way... compiling msvc++ 4.1 (!!!), understand if cannot duplicate, please help.
thanks,
dennis. (sorry long post)

put template code directly in header, not in separate cpp file.

see this previous question background.

edit: btw see on old compiler - problem may insurmountable, vc6 sketchy templates.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -