How to extend existing template in C++?
I am working with legacy code of a template that is based on
template<class keyType, class dType> Foo Bar(const dType val)
Somewhere in that code is a place where someone made a debug function like this:
virtual void getDebugStr01(int db_id, OFCString & db_str)
{
//OFCStringStream ss;
if(db_id==0)
{
map<keyType, dType>::iterator it = m_stateData.begin();
for(;it!=m_stateData.end();it++)
{
(it->second).getDebugStr01(db_str);
}
}
}
Now, I would need to use the template class with a float. Is there anyway to do this?
Currently I get a:
error C2228: left of '.getDebugStr01' must hav开发者_运维知识库e class/struct/union
getDebugStr01()
should be a member of a class/struct
. virtual
methods cannot be stand alone.
You can do something like,
Foo Bar (const float f)
{
...
}
精彩评论