【发布时间】:2013-03-10 11:15:19
【问题描述】:
谁能解释我为什么会得到:
错误 C2064:术语不计算为采用 1 个参数的函数
换行:
DoSomething->*pt2Func("test");
这个类
#ifndef DoSomething_H
#define DoSomething_H
#include <string>
class DoSomething
{
public:
DoSomething(const std::string &path);
virtual ~DoSomething();
void DoSomething::bar(const std::string &bar) { bar_ = bar; }
private:
std::string bar_;
};
#endif DoSomething_H
和
#include "DoSomething.hpp"
namespace
{
void foo(void (DoSomething::*pt2Func)(const std::string&), doSomething *DoSomething)
{
doSomething->*pt2Func("test");
}
}
DoSomething::DoSomething(const std::string &path)
{
foo(&DoSomething::bar, this);
}
【问题讨论】:
-
你没有打错这一行:
void foo(void (DoSomething::*pt2Func)(const std::string&), doSomething *DoSomething)?它不应该包含DoSomething* doSomething吗?也就是最后2个字换了?
标签: c++ function-pointers