【发布时间】:2010-09-19 07:16:27
【问题描述】:
如果我有例如包含函数的 A 类:
//this is in A.h
friend const A operator+ (const A& a,const A& b);
friend const A operator* (const A& a,const A& b);
这是一个全球性的(据我所知)。这个函数在 A.cpp 中实现。
现在,我有 B 类,其中也包含函数和成员:
//this is in B.h
friend const B operator+ (const B& a,const B& b);
friend const B operator* (const B& a,const B& b);
A _a;
我想在 B.h 中创建单个方法,而不是使用两个单独的方法:
static const B Calc(const B&, const B&, funcP);
在 B.cpp 和 funcP 中实现的 typedef 是指向上述函数的指针:
typedef const A (*funcP) ( const A& a, const A& b);
但是当我试图在函数内部调用 Calc(..) 时,我得到了这个错误: “未解决的重载函数类型”。我这样称呼它:
friend const B operator+ (const B& a,const B& b){
...
return B::Calc(a,b, &operator+);
}
我做错了什么?
【问题讨论】:
-
您的代码没有显示
const B&与const A&有任何关系。 -
请发布完整的代码。鉴于您遇到的问题,如果不查看更多代码,就不可能找出问题所在。
标签: c++ function-pointers