提问者:小点点

无法转换相同类型G++


我在用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;
};


共2个答案

匿名用户

*在实现中位于错误的位置。 使用

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)。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(转换|类型|g++)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?