我在用g++编译时出现了这个错误,但是它是同一个类型,所以我不知道该怎么做:
error: cannot convert ‘IOperand*’ to ‘IOperand Factory:: *’ in return
68 | return (tmp->retOperand(type, value));
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
| |
| IOperand*
下面是代码:
IOperand Factory::*retOperand(eOperandType type, const std::string &value)
{
methodPtr_t mfPtr;
std::map<eOperandType, methodPtr_t>::iterator it;
return (NULL);
}
static IOperand Factory::*createOperand(eOperandType type, const std::string &value)
{
std::unique_ptr<Factory> tmp = std::make_unique<Factory>();
return (tmp->retOperand(type, value));
}
下面是我的标题:
class Factory {
public:
Factory();
~Factory();
static IOperand *createOperand(eOperandType type, const std::string &value);
IOperand *retOperand(eOperandType type, const std::string &value);
protected:
private:
using methodPtr_t = IOperand *(Factory::*)(const std::string &);
IOperand *createInt8(const std::string &value);
IOperand *createInt16(const std::string &value);
IOperand *createInt32(const std::string &value);
IOperand *createFloat(const std::string &value);
IOperand *createDouble(const std::string &value);
IOperand *createBigDecimal(const std::string &value);
std::map<eOperandType, methodPtr_t> _methods;
};
*
在实现中位于错误的位置。 使用
IOperand* Factory::retOperand(...)
{
...
}
static IOperand* Factory::createOperand(...)
{
....
}
应该是
IOperand* Factory::retOperand(eOperandType type, const std::string &value) { /*..*/}
// ^ X
IOperand* Factory::createOperand(eOperandType type, const std::string &value) { /**/ }
// ^ X
和
IOPERAND*
与IOPERAND
:前者只是IOPERAND
上的指针,后者是成员指针(用于类Factory
,成员类型应为IOPERAND
)。