C ++ Boost :: serialization在调用函数的参数中“无匹配函数可供调用”到类的构造函数

伊托莱特

我的实际问题在下面的粗体字中,但这是我的问题所在:

我正在尝试使用Boost :: serialization来保存和恢复玩家的状态。我在http://www.boost.org/doc/libs/1_56_0/libs/serialization/doc/tutorial.html#simplecase中阅读了该教程,但不确定如何

boost::archive::text_iarchive 

作品。

我正在假设以下几行

boost::archive::text_iarchive inArchive(playerfile);
    inArchive >> target;

将根据播放器文件的相应文本文件初始化目标?

我在假设的情况下编写了以下函数:

bool SavePlayerState(Player *target)
{
std::string fileName = (target->name) + ".playerfile";
std::ofstream playerfile(fileName);

if(!playerfile.is_open())
{
    s_al_show_native_message_box(display, "SAVE FAILURE", "SAVE FAILURE", fileName + "could not be created/opened.",
                             NULL, ALLEGRO_MESSAGEBOX_ERROR);

    return false;
}

boost::archive::text_oarchive outArchive(playerfile);
outArchive << target;

return true;
}

bool LoadPlayerState(std::string playerName, Player *target)
{
std::string fileName = playerName + ".playerfile";
std::ifstream playerfile(fileName);

if(!playerfile.is_open())
{
    s_al_show_native_message_box(display, "LOAD FAILURE", "LOAD FAILURE", fileName + "could not be found/opened.",
                             NULL, ALLEGRO_MESSAGEBOX_ERROR);

    return false;
}

boost::archive::text_iarchive inArchive(playerfile);
inArchive >> target;

return true;
}

为了测试目的,它们在main()中被调用:

int main(int argc, char *argv[])
{
//...

player = new Player(5,5); // There is a Player*player; declared elsewhere
LoadPlayerState("player", player); //Load the file with this name, target is player object
beings.push_back(player);

//The game's operations...

SavePlayerState(player);

delete player;

//...

return 0;
}

SavePlayerState(player); 可以正常工作,并且我发现目录中已经创建了player.playerfile。但是LoadPlayerState(“ player”,player); 给我以下错误:

C:\Development\Libraries\boost\boost\serialization\access.hpp|132|error: no matching function for call to 'Player::Player()'|

我不知道为什么构造函数应该有问题,或者为什么Save可以工作而不是Load。我不是在尝试创建新的Player对象,而是根据存档来调整现有目标Player的形状。为了使这项工作有效,我需要更改什么?

我的球员班:

#ifndef PLAYER_H_INCLUDED
#define PLAYER_H_INCLUDED

#include "being.h"
#include "extfile.h"

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/vector.hpp>

class Player: public Being
{
friend class boost::serialization::access;
template<class PlayerArchive>
void serialize(PlayerArchive & par, const unsigned int version)
{
    par & boost::serialization::base_object<Being>(*this);

    par & active;
    //par & various things
}

public:
Player(bool savedPlayer);
Player(int spawnXCell, int spawnYCell);
~Player();
//Functions
};

//Prototype to the save and Load state functions mentioned previously are found here.


#endif // PLAYER_H_INCLUDED

如果有帮助,这是我完整的构建消息日志:

> || ===构建:在Roguelike中进行调试(编译器:GNU GCC编译器)=== |
> C:\ Development \ Libraries \ boost \ boost \ serialization \ access.hpp ||实例化为“静态void boost :: serialization :: access :: construct(T *)[with T = Player]”:|
> C:\ Development \ Libraries \ boost \ boost \ serialization \ serialization.hpp | 93 |要求来自'void boost :: serialization :: load_construct_data(Archive&,T *,unsigned int)[with Archive = boost :: archive :: text_iarchive; T =玩家]'|
> C:\ Development \ Libraries \ boost \ boost \ serialization \ serialization.hpp | 158 |要求来自'void boost :: serialization :: load_construct_data_adl(Archive&,T *,unsigned int)[with Archive = boost :: archive :: text_iarchive; T =玩家]'|
> C:\ Development \ Libraries \ boost \ boost \ archive \ detail \ iserializer.hpp | 341 |从'void boost :: archive :: detail :: pointer_iserializer :: load_object_ptr(boost :: archive :: detail :: basic_iarchive& ,void *,unsigned int)const [with Archive = boost :: archive :: text_iarchive; T =玩家]'|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.cpp | 76 |从此处要求|
> C:\ Development \ Libraries \ boost \ boost \ serialization \ access.hpp | 132 |错误:没有匹配的函数调用'Player :: Player()'|
> C:\ Development \ Libraries \ boost \ boost \ serialization \ access.hpp | 132 |注意:候选对象为:|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.cpp | 8 |注:Player :: Player(int,int)|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.cpp | 8 |注意:候选人需要2个参数,提供了0个|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.cpp | 3 |注:Player :: Player(bool)|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.cpp | 3 |注:候选人期望1个参数,提供0个|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.h | 12 |注意:Player :: Player(const Player&)|
> C:\ Development \ Projects \ Roguelike \ Roguelike \ player.h | 12 |注意:候选人期望1个参数,提供0个|
|| ===构建失败:1个错误,5个警告(0分钟,4秒)=== |

非常感谢。如果需要任何其他信息,我将在后面附加。

一些程序员哥们

错误消息非常清楚:

没有匹配的函数来调用'Player :: Player()'

您的类中必须具有默认构造函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用boost :: filesystem :: path作为参数的C ++构造函数调用-没有任何反应

来自分类Dev

使用boost :: function通过函数指针调用C ++类方法

来自分类Dev

从C#中的参数化构造函数调用无参数构造函数?

来自分类Dev

初学者C ++,构造函数中的“无匹配函数调用”

来自分类Dev

Boost python,嵌入式时从python调用c ++函数

来自分类Dev

C ++的boost :: python包装对象的析构函数调用

来自分类Dev

C ++的boost :: python包装对象的析构函数调用

来自分类Dev

C ++ Boost函数回调。如何调用函数作为回调并在内部传递参数?

来自分类Dev

C ++构造函数调用

来自分类Dev

C ++为类调用构造函数

来自分类Dev

C ++ Python Boost中的Friend函数

来自分类Dev

在派生类 C++ 的构造函数中调用基类的构造函数

来自分类Dev

C#测试-构造函数调用中的模拟类

来自分类Dev

如何使用带有 Boost.Python 的 std::map 或 std::vector 参数的构造函数包装 C++ 类?

来自分类Dev

如何使用在Boost Fusion容器中实例化的类型的参数调用构造函数?

来自分类Dev

同一类的另一个构造函数中的c ++调用构造函数

来自分类Dev

C ++-构造函数调用构造函数

来自分类Dev

C++ Boost:在构造函数之后初始化端点

来自分类Dev

C ++中的直接构造函数调用

来自分类Dev

C ++中的直接构造函数调用

来自分类Dev

在int方法C ++中调用构造函数

来自分类Dev

从简单的python类/函数调用Boost Python函数

来自分类Dev

未调用C ++构造函数

来自分类Dev

C ++不同的构造函数调用

来自分类Dev

C ++构造函数未调用

来自分类Dev

C ++调用线程构造函数

来自分类Dev

调用父构造函数C ++

来自分类Dev

绑定C ++函数并以类为参数调用Lua函数

来自分类Dev

C ++“无匹配函数可调用”和“无已知参数转换”

Related 相关文章

  1. 1

    使用boost :: filesystem :: path作为参数的C ++构造函数调用-没有任何反应

  2. 2

    使用boost :: function通过函数指针调用C ++类方法

  3. 3

    从C#中的参数化构造函数调用无参数构造函数?

  4. 4

    初学者C ++,构造函数中的“无匹配函数调用”

  5. 5

    Boost python,嵌入式时从python调用c ++函数

  6. 6

    C ++的boost :: python包装对象的析构函数调用

  7. 7

    C ++的boost :: python包装对象的析构函数调用

  8. 8

    C ++ Boost函数回调。如何调用函数作为回调并在内部传递参数?

  9. 9

    C ++构造函数调用

  10. 10

    C ++为类调用构造函数

  11. 11

    C ++ Python Boost中的Friend函数

  12. 12

    在派生类 C++ 的构造函数中调用基类的构造函数

  13. 13

    C#测试-构造函数调用中的模拟类

  14. 14

    如何使用带有 Boost.Python 的 std::map 或 std::vector 参数的构造函数包装 C++ 类?

  15. 15

    如何使用在Boost Fusion容器中实例化的类型的参数调用构造函数?

  16. 16

    同一类的另一个构造函数中的c ++调用构造函数

  17. 17

    C ++-构造函数调用构造函数

  18. 18

    C++ Boost:在构造函数之后初始化端点

  19. 19

    C ++中的直接构造函数调用

  20. 20

    C ++中的直接构造函数调用

  21. 21

    在int方法C ++中调用构造函数

  22. 22

    从简单的python类/函数调用Boost Python函数

  23. 23

    未调用C ++构造函数

  24. 24

    C ++不同的构造函数调用

  25. 25

    C ++构造函数未调用

  26. 26

    C ++调用线程构造函数

  27. 27

    调用父构造函数C ++

  28. 28

    绑定C ++函数并以类为参数调用Lua函数

  29. 29

    C ++“无匹配函数可调用”和“无已知参数转换”

热门标签

归档