vendredi 29 novembre 2019

Iterating over a vector containing pointers in c++

I got a function that accepts a pointer to a rapidjson::Value type and stores the item at that location into a rapidjson::Value of type kArrayType.

void addBlock(rapidjson::Value* block) {
    blocksArray.PushBack(*block, allocator);
}

This function works as expected.

To extend this I want to add a function that can take a vector of these pointers as an input. I tried this doing:

void addBlocks(std::vector<rapidjson::Value*> blocks) {
    for (const rapidjson::Value& block : blocks) {
        blocksArray.PushBack(*block, allocator);
    }
}

This does not work however. It gives me two red waves in Visual Studio.

The first one beneath block in the parameter declaration of the function, saying:

C++ no suitable constructor exists to convert from to...

And the second one beneath the * in the call to PushBack(), saying:

C++ no operator matches these operands operand types are: * const rapidjson::Value

My guess is that I am doing something very basic wrong that I am just missing.

Aucun commentaire:

Enregistrer un commentaire