【发布时间】:2021-05-03 22:46:31
【问题描述】:
我知道了:
#include<iostream>
#include <functional>
using namespace std;
template<class T>
class A
{
public:
template<class S>
function<S(T)> transform;
};
int main()
{
obiekt.transform = [=] (int element) { return (float)element; };
}
如何使转换函数具有第二种类型的通用性?我不是在问如何向A 添加第二种类型,例如A<int, float>。我知道该怎么做。
【问题讨论】:
-
如果这是合法的,则意味着
A<int>对象包含function<void(int)>成员对象、不同的function<int(int)>成员对象、不同的function<std::vector<char>(int)>成员对象等。
标签: c++ templates generics lambda