mercredi 22 février 2017

How to fix "no instance of overloaded function" in vector push_back?

I want to write a function which takes as input a pointer to a vector pointer which point to a string (Dictionnary) and a pointer which points to a char (p). The function will check if the char is in the Dictionnary and if it isn't there it adds the p in the vector Dictionnary.

My code:

#include <iostream>
#include <string>
#include <vector>
using std::string;
using std::vector;

std::vector<string *> dictionnary;

void manageDictionnary(vector<string *> * dictionnary, char *p) {
    for (unsigned int i = 0; i < (*dictionnary).size(); i++) {
        string * pstring = (*dictionnary).at(i);
        if ((*pstring).compare(p)) {
            (*dictionnary).push_back(p);
        }
    }
}

However, the visual studio compiler shows I have an error in the if statement just before the push_back method (.). When I hover on the error, it says "no instance of overloaded function".

I added the std::vector<string *> dictionnary; at the beginning, still cannot figure out where is the problem.

Aucun commentaire:

Enregistrer un commentaire