函数传递映射时出现异常错误

Unusual Error in function passing map

本文关键字:异常 错误 映射 函数      更新时间:2023-10-16

我不太了解可能导致这种情况的全部情况,我对这个函数做了相当多的更改,但似乎这不是函数问题,而是调用这个函数的函数中的问题。

main(){
    //set up variables...
    //theVector is made on the spot using a constructor
    Player thePlayer(proper, variables, here);
    Map theMap();
    theMap.functionThatAddsValues(stuff);
    std::map<ObjectName, Drawing> theMap;
    //This map is filled by using theMap[ObjectName::TheObject] since
    //this is mapped by its first values being enumerated data.
    movement(theVector, thePlayer, theMap, theDrawings);
    //other stuff
}
void movement(sf::Vector2f theVector, Player thePlayer, Map theMap, std::map<ObjectName, Drawing> theDrawings){
    //use the joyous variables
}

如果此信息太模糊,我可以在文件的后面做一个代码转储链接,我只是认为代码太大而无法完整地发布在这里,因为它既有函数又有我计划删除的代码行由于弃用,以及尚未完成的功能(如错误所示)。

编辑:忘了提到错误:

/home/sir-lulzalot/Testland/sfml/SFMLink/main.cpp:277: error:
 undefined reference to `movement(sf::Vector2<float>, Player, Map, std::map<ObjectName,
 Drawing, std::less<ObjectName>, std::allocator<std::pair<ObjectName const, Drawing> > >)'

编辑2:这是主要的转储.cpp http://pastebin.com/TyCzWyfK

编辑3:德普找到了答案。

首先,这一行可能不会像你认为的那样做:

Map theMap();

这将声明一个名为 theMap 的无参数函数,该函数返回一个 Map 。(原因见此处)。我猜您可能打算创建一个名为 theMap 的类型为 Map 的变量,在这种情况下,您需要删除括号。

然后对类型为 std::map<ObjectName, Drawing> 的变量使用相同的名称 (theMap )。我要冒险再猜测一下,说你的意思是这个变量被称为theDrawing

除此之外,您还没有显示变量theVectortheDrawings的代码,所以如果您想要更多答案,我建议您整理一个SSCCE代码。或者换句话说,不要遗漏生成错误所需的任何代码。

这是一个链接器错误。

您没有一致的声明和定义。

这是文件顶部移动函数的声明:

void movement(sf::Vector2f, Player, Map, std::map<ObjectName, Drawing>);

这是移动函数的定义:

void movement(sf::Vector2f theVector, Player &thePlayer, Map &theMap, std::map<ObjectName, Drawing> theDrawings){

请注意,定义采用Player&,而声明显示 Player