vendredi 3 juillet 2020

type/value mismatch at argument 1 in template parameter list

I found that the problem is in std::map but I have no clue why.

ObjectFactory.hpp

template <
        class TAbstractProduct,
        typename IdentifierType,
        class TProductCreator = std::function<TAbstractProduct*()>
          >
class ObjectFactory
{
public:
    using product_type = TAbstractProduct;
    using id_type = IdentifierType;
    using creator_type = TProductCreator;

    ObjectFactory() = default;

    bool registerType(const id_type& id, creator_type callback) {
        typename TCallbackMap::value_type el{id, callback};
        auto res = callbacks.insert(el);
        return true;
    }

    bool unregisterType(const id_type& id) {
        return (callbacks.erase(id) == 1);
    }

    product_type* create(id_type id) const {
        auto iterator = callbacks.find(id);
        if (iterator != callbacks.end()) {
            return iterator->second();
        }
    }

private:
    using TCallbackMap = std::map<IdentifierType, TProductCreator>;
    TCallbackMap callbacks;
};

Shape.hpp

class Shape
{
public:
    virtual std::string text() const {
        return "Shape";
    }
    static int id() {
        return 0;
    }
};

main.cpp

using ShapeFactory = ObjectFactory<Shape, int, std::function<Shape*()>>;

int main() {
    ShapeFactory* factory = new ShapeFactory(); //crashes
}

Shape It seems to me that some types are not fully determined in the scope of ShapeFactory, so map cannot properly process it, but I don't understand which.

Issue text is: error: type/value mismatch at argument 1 in template parameter list for 'template struct first' if (__p.first < __n) ^~~

Aucun commentaire:

Enregistrer un commentaire