简体   繁体   English

map.insert:“无效参数”错误,对<enum,vector <* >>

[英]map.insert: “Invalid arguments” error with pair<enum,vector<*>>

EDIT 4: Ok, I narrowed the problem down to a small cpp file giving the same error message which everyone can reproduce: 编辑4:好的,我把问题缩小到一个小的cpp文件,给出了相同的错误信息,每个人都可以重现:

#include<vector>
#include<map>
using namespace std;

namespace{enum class Colors{Black,White};}

class dummyClass{};

class MapTest
{
    vector<dummyClass*> Dummys;
    map<Colors,vector<dummyClass*>> dummyMap;
public:
    MapTest()
    {
        Dummys.push_back(new dummyClass);
        Dummys.push_back(new dummyClass);
        dummyMap.insert(make_pair(Colors::White,Dummys));
    }
    ~MapTest()
    {
        for(unsigned int i=0;i<Dummys.size();++i)
        {
            delete Dummys[i];
        }
        Dummys.clear();
        dummyMap.clear();
    }

};

int main()
{
    MapTest m;
}

EDIT 3: In case anyone wonders. 编辑3:如果有人想知道。 I delete all Pointers in the destructor. 我删除了析构函数中的所有指针。 Didn't post it since I figured it's not relevant to the problem 没有发布,因为我认为它与问题无关

EDIT 2: Added more details in the .cpp file. 编辑2:在.cpp文件中添加了更多详细信息。 The classes "Bauer" and "Position" shouldn't be of any relevance. “鲍尔”和“职位”这两个课程不应该有任何关联。

My header file match.h: 我的头文件match.h:

#include <map>
#include"Bauer.h"
class Match
{
    int counter{0};
    std::vector<Figuren*> allFiguresWhite;
    std::vector<Figuren*> allFiguresBlack;
    std::map<Farben,std::vector<Figuren*>> samePlayerFig;
    std::map<Farben,std::vector<Figuren*>> otherPlayerFig;
   //more code...
}

"Farben" is just a enum : enum class Farben{black, white}; “Farben”只是一个枚举: enum class Farben{black, white}; In my match.cpp I try at one point to insert a par into the map: 在我的match.cpp中,我尝试在一点上将par插入到地图中:

#include "match.h"
using namespace std;

Match::Match()
{
    cout<<"Let the games begin\n";
    InitGame();
}

void Match::InitGame()
{
    for(int i=1;i<9;i++)
    {
        allFiguresWhite.push_back(new Bauer(Position{2,i},Farben::white, counter++));
        allFiguresBlack.push_back(new Bauer(Position{7,i},Farben::black,counter++));
    }
    samePlayerFig.insert(make_pair(Farben::white,allFiguresWhite));
    //more code...
}

Unfortunately I get the compiler error "Invalid arguments' " in this line with "insert" beeing underlined in red. 不幸的是,我在这一行中得到了编译器错误“Invalid arguments”,其中“insert”beeing用红色下划线标出。 Any idea what I did wrong? 知道我做错了什么吗?

EDIT: Here is the complete error message 编辑:这是完整的错误消息

Invalid arguments ' Candidates are: std::pair>>>,bool> insert(const std::pair>> &) std::pair>>>,bool> insert(#10000 &&) void insert(std::initializer_list>>>) std::_Rb_tree_iterator>>> insert(std::_Rb_tree_const_iterator>>>, const std::pair>> &) std::_Rb_tree_iterator>>> insert(std::_Rb_tree_const_iterator>>>, #10000 &&) void insert(#10000, #10000) ' match.cpp /chessGame line 17 Semantic Error 无效的参数'候选者是:std :: pair >>>,bool> insert(const std :: pair >>&)std :: pair >>>,bool> insert(#10000 &&)void insert(std :: initializer_list >>>)std :: _ Rb_tree_iterator >>> insert(std :: _ Rb_tree_const_iterator >>>,const std :: pair >>&)std :: _ Rb_tree_iterator >>> insert(std :: _ Rb_tree_const_iterator >>>,#10000 && void void insert(#10000,#10000)'match.cpp / chessGame第17行语义错误

Ok, It seems to be a Eclipse specific error. 好吧,这似乎是Eclipse特定的错误。 I compiled the Test programm from the command line using "g++ main.cpp -o main" and it works fine. 我使用“g ++ main.cpp -o main”从命令行编译了Test programm,它运行正常。 Gonna look into it why it doesn't work on eclipse. 要看看为什么它不适用于eclipse。 So far I've compiled a lot of projects and never had any compiler issues. 到目前为止,我已经编译了很多项目,从来没有任何编译器问题。

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

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