jeudi 2 juillet 2015

I'm trying to pass in a std::vector<std::string> to a void* for use in a callback function which requires a void* to be passed to it. The callback is a sqlite_exec callback. So how can I pass in a std::vector<std::string> into such a callback?

static int cb_vector(void* vec, int argc, char**argv, char**colNm){
    std::vector<std::string>* myvec = (std::vector<std::string>*)vec;
    for(int i = 0; i < argc; i++){
        myvec->push_back(argv[i]);
    }
    return 0;
}

void myfunc(){
    std::vector<std::string> vec;
    int rc = sqlite3_exec(_db, SQL, cb_vector, (void*)&vec, NULL);
}

I have already looked the following resources, but they did not answer my quesion.

Aucun commentaire:

Enregistrer un commentaire