template <typename Func> struct Stage { Func function; Stage(Func func) : function(func)…
- User
template struct Stage { Func function;
Stage(Func func) : function(func) {}}; class A{ public: A(std::string x) : y(x) {} std::tuple<std::string, int> func1(std::string && x) { std::string t = x + y; std::reverse(t.begin(), t.end()); int len = t.length(); return std::make_tuple(std::move(t), len); } void test() { Stage s(func1); } private: std::string y; }; 可以这样写吗
- Assistant
您提供的代码尝试在类
A的成员函数test中将成员函数func1传递给模板结构体Stage。然而,直接这样写会导致一些问题。以下是详细分析和解决方案:问题分析
-
成员函数指针与普通函数指针的区别:
-