当我遇到函数模板template<typename Stream>
时,我正在查看ros中的一些代码。稍后在函数中,实例的方法被称为stream.next(t.x);
我尝试搜索,无法找到存在此类实例的任何示例。
这是可能的,为什么在这种情况下使用模板?
namespace ros
{
namespace serialization
{
template<>
struct Serializer<MyVector3>
{
template<typename Stream>
inline static void write(Stream& stream, const MyVector3& t)
{
stream.next(t.x);
stream.next(t.y);
stream.next(t.z);
}
template<typename Stream>
inline static void read(Stream& stream, MyVector3& t)
{
stream.next(t.x);
stream.next(t.y);
stream.next(t.z);
}
inline static uint32_t serializedLength(const MyVector3& t)
{
uint32_t size = 0;
size += serializationLength(t.x);
size += serializationLength(t.y);
size += serializationLength(t.z);
return size;
}
};
} // namespace serialization
} // namespace ros