- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
代码应该解释我的困难。虽然代码本身没什么意义,但我打算在 MyClass 中添加容器,并使用带有成员函数的算法。
#include <cstdlib>
#include <algorithm>
#include <functional>
using namespace std;
class MyClass
{
public:
MyClass() { a = 0; }
~MyClass() {}
private:
int a;
bool tiny_test (int);
int Func();
};
bool MyClass::tiny_test (int b)
{
return a == b;
}
int MyClass::Func()
{
// does not compile
(mem_fun(&MyClass::tiny_test))(this);
// commented below is another attempt, also no success
//mem_fun1_t<bool, MyClass, int> tmp_functor = mem_fun(&MyClass::tiny_test);
//tmp_functor(this);
return 0;
}
int main(int argc, char** argv)
{
return 0;
}
非常感谢!顺便说一句,我没有使用静态成员函数,只是因为我相信它必须适用于非静态成员函数。附言Eric、Jarod42,感谢您的及时回复!
最佳答案
bool MyClass::tiny_test (int b)
{ // ^^^^^ You missed this argument
return a == b;
}
试试这个:
// Supply one more argument. E.g., 3
(mem_fun(&MyClass::tiny_test))(this, 3);
关于c++ - 为非静态成员函数创建一个 unary_function 仿函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31712955/
代码应该解释我的困难。虽然代码本身没什么意义,但我打算在 MyClass 中添加容器,并使用带有成员函数的算法。 #include #include #include using namespa
使用 VS2005 在 Windows 上工作并努力理解我收到的错误消息。如果之前有人问过这个问题,我很抱歉。我找不到它。 我正在测试的类: #include using std::unary_fu
我有一个看起来像这样的类。 class A { public: void doSomething(); } 我有一组这些类。我想对数组中的每个项目调用 doSomething() 。使用算法
我遇到了类模板 std::unary_function 和 std::binary_function。 template struct unary_function { typedef Ar
我只是在为一组仿函数寻找一个方便的基类,这些仿函数基于获取和 int 并返回 void。 考虑使用 std/functional 仿函数基本上是 unary_function与 operator()
这个问题在这里已经有了答案: Where and why do I have to put the "template" and "typename" keywords? (8 个答案) 关闭 9
我阅读了有关二元和一元函数的教程。我了解它们的结构,但我无法想象在哪种情况下我需要这些功能。你能举个例子来说明它们的用法吗? http://www.cplusplus.com/reference/st
这是导致我出现一些问题的代码,尝试构建并获取错误: 'unary_function base class undefined' and 'unary_function' is not a member
当如下检查从 std::unary_function 派生的仿函数时 struct IsInterestingMsg : public std::unary_function Lint 弹出以下信息/
我有一个继承自 unary_function 的仿函数类: template class Matcher : public std::unary_function { private: int
这是我的代码: using namespace std; class Pixel { public: bool AreSamplesIdentical() const {
我发现 binary_function 已从 C++11 中删除。我想知道为什么。 C++98: template struct less : binary_function { bool o
std::unary_function特性在 c++11 中被弃用并在 c++17 中被删除。但是使用 c++17 编译器标志,这段代码仍然可以编译: struct less_than_7 : std
binder2nd 派生自 unary_function。 以下代码片段不起作用: greater g; //greater is derived from binary_function /
我是一名优秀的程序员,十分优秀!