의 나는 다음과 같은 정의가 있다고 가정 해 봅시다 : 내가 전화하려고C++ 포인터가 아닌 함수 포인터
ScriptInterpreter::eval(ScriptInterpreter::cell cell, environment * env)
{
// ...
ScriptInterpreter::cell c;
c.proc = &ScriptInterpreter::proc_add;
return (c.*proc_)(exps);
}
라인에서 :
class ScriptInterpreter {
public:
class cell;
typedef ScriptInterpreter::cell (ScriptInterpreter::*proc_t) (const std::vector<cell> &);
class cell {
public:
proc_t proc;
};
ScriptInterpreter::cell proc_add(const std::vector<cell> & c);
};
그리고 다음 코드 진행을 함수 포인터 오류가 발생했습니다
error: called object type 'proc_t' (aka 'ScriptInterpreter::cell (ScriptInterpreter::*)(const std::vector<cell> &)') is not
a function or function pointer
func 앞에 *를 추가하면 다음과 같이 표시됩니다.
error: use of undeclared identifier 'proc_'
가 이미 Callback functions in c++ 그 종류의 다른 문제 보았다, 그러나 아무것도 정말 나에게 잘못 또는 내 오류에 대한 정보를 제공하는 어떤 힌트를주지 않았다 :
ScriptInterpreter::cell c = (proc_cell.*proc_)(exps);
는이 생산하고 있습니다. 나는 두 번이나 그런 종류의 이름을 갖고 있지는 않습니다. 또한 what is an undeclared identifier error and how do i fix it을 읽은 후에 나는 모든 것이 괜찮은지 확신합니다.
그래서 내가 뭘 잘못하고 있니?
편집 : 포인터 - 투 - 멤버 타입의 포인터를 통해 멤버 함수를 호출하기 위해 실제 코드 대신
첫째, 코드에는 'B'가 없습니다. 오직'A :: B'. 'main'에 대한 실제 코드를 게시하는 것이 좋습니다. 그러면 사람들이 여러분이 말하는 것을 이해할 수 있습니다. – AnT
'A' 멤버 함수에 대한 포인터이기 때문에 호출하려면'A' (B가 아님)의 객체가 필요합니다. – songyuanyao
B는 A에 속하지 않습니다 – Raindrop7