本文 主要是解决一些实际项目中,添加一些耗时操作,放到线程队列中,处理完成后返回给UI线程;
用到一些知识点:
Functor 仿函数:又称为函数对象(function object)是一个能行使函数功能的类,其实现就是类中实现一个operator();
目的:迭代和计算逻辑分离;
//----------------------------------------仿函数;-------------------------------------------------------------------
//类是模板;
template<typename T>
class displayA
{
public:
void operator()(const T& x)
{
m_data = x;
cout << x << " ";
}
T m_data;
};
class display
{
public:
//类内的函数是模板;
template<typename T>
void operator()(const T& x)
{
cout << x << " ";
}
};
// 仿函数 添加多个参数;
class displayB
{
public:
displayB(int lenth) : m_lenth(lenth) {}
template<typename T>
void operator()(const T& x)
{
cout << "x: " << x << "lenth: " << m_lenth <&
用到一些知识点:
Functor 仿函数:又称为函数对象(function object)是一个能行使函数功能的类,其实现就是类中实现一个operator();
目的:迭代和计算逻辑分离;
//----------------------------------------仿函数;-------------------------------------------------------------------
//类是模板;
template<typename T>
class displayA
{
public:
void operator()(const T& x)
{
m_data = x;
cout << x << " ";
}
T m_data;
};
class display
{
public:
//类内的函数是模板;
template<typename T>
void operator()(const T& x)
{
cout << x << " ";
}
};
// 仿函数 添加多个参数;
class displayB
{
public:
displayB(int lenth) : m_lenth(lenth) {}
template<typename T>
void operator()(const T& x)
{
cout << "x: " << x << "lenth: " << m_lenth <&