简体   繁体   English

C ++没有匹配函数来调用向量中的擦除

[英]C++ no matching function for call to erase in vector

I have been researching and trying to figure out this error for hours with no success. 我一直在研究,试图找出这个错误已经有好几个小时没有成功。 I am unable to erase from a vector, given an index to erase. 给定要删除的索引,我无法从向量中删除。 The function to erase a given index is in tuple.cpp, as outlined in tuple.h. 删除给定索引的功能在tuple.cpp中,如tuple.h中所述。

tuple.h: tuple.h:

#pragma once
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Tuple {
    private:
        vector<string> tuVec;
    public:
        Tuple() {};
        string toString() const;
        void eraseFromVec(int index) const;
        bool operator< (const Tuple &right) const {
            string temp = toString();
            string temp2 = right.toString();
            return temp < temp2;
        }
};

tuple.cpp: tuple.cpp:

#include "tuple.h"

void Tuple::eraseFromVec(int index) const {
    tuVec.erase(tuVec.begin() + index);
    return;
}

Each Tuple object is a member of a set, which is a member of class Relation. 每个Tuple对象都是集合的成员,集合是Relation类的成员。

Relation.h: Relation.h:

#pragma once

#include "tuple.h"
#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <iterator>

using namespace std;

class Relation {
    private:
        string name;
        set<Tuple> tuples;
    public:
        Relation(string rName, Scheme rScheme);
        void addTuple(Tuple newTuple);
};

And here is the code that calls the erase function: 这是调用擦除功能的代码:

set<Tuple>::iterator it;
    for(it = tuples.begin(); it != tuples.end(); ++it) {
        int size = it->tuVec.size() - 1;
        int i;
        for(i = size; i > -1; --i) {
            bool isIn = false;
            int j;
            int size2 = tempRel.toKeep.size();
            for(j = 0; j < size2; ++j) {
                if(//condition) {
                    isIn = true;
                }
            }
            if(!isIn) {
                it->eraseFromVec(i);
            }
        }
    }

Here is the error message I'm getting: (I tried typing it here but it didn't work for some reason, so I'm attaching a picture of it) 这是我收到的错误消息:(我尝试在此处键入它,但是由于某种原因它不起作用,所以我附上了它的图片)

My error message 我的错误讯息

I hope this hasn't been asked before. 我希望以前没有问过。 I've been searching the internet for hours trying to find a solution but I've been unable to. 我已经在互联网上搜索了数小时,试图找到解决方案,但是一直无法。 I'd appreciate any help. 我将不胜感激。

It seems that your problem is that your function eraseFromVec has a const qualifier. 看来您的问题是您的函数eraseFromVec具有const限定符。 But it calls the erase function of std::vector which is non const. 但是它调用了std::vectorerase函数,该函数不是const。 Just remove the const qualifier and it should work fine. 只需删除const限定符,它就可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM