由买买提看人间百态

topics

全部话题 - 话题: iidbase
(共0页)
z***e
发帖数: 14
1
来自主题: Programming版 - 问一个C++ template的问题
1. You can dynamic-cast the in object to target types. If it fails, do
nothing. Otherwise, get the id from the casted type.
2. If there is no target type known-in-advance, for example you don't want
to list all possible target types or it is created by third party, you can
use template constrain in definition. Some thing like this:
bool Comparer (T t1, T t2) where T : IIDBase
{
return t1.Equals(t2);
}
IIDBase is the interface:
Interface IIDBase
{
int GetID();
}
Then derive a
(共0页)