Невозможно преобразовать тот же тип g ++ - PullRequest
0 голосов
/ 13 июля 2020

У меня эта ошибка при компиляции с 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 ]

1 голос
/ 13 июля 2020

* находится не в том месте в реализациях. Используйте

IOperand* Factory::retOperand(...)
{
...
}

static IOperand* Factory::createOperand(...)
{
....
}
1 голос
/ 13 июля 2020

Должно быть

IOperand* Factory::retOperand(eOperandType type, const std::string &value) { /*..*/}
//      ^          X
IOperand* Factory::createOperand(eOperandType type, const std::string &value) { /**/ }
//      ^          X

И

IOperand* не то же самое, что IOperand Factory::*: первое - просто указатель на IOperand, второе - член указатель (для класса Factory, а тип элемента должен быть IOperand).

...