[英]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 have class/struct/union
getDebugStr01()
should be a member of a class/struct
. getDebugStr01()
应该是class/struct
的成员。 virtual
methods cannot be stand alone. virtual
方法不能孤立。
You can do something like, 你可以做类似的事情,
Foo Bar (const float f)
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.