gpt4 book ai didi

c++ - Boost Python签名不匹配问题

转载 作者:行者123 更新时间:2023-11-28 01:05:48 25 4
gpt4 key购买 nike

我发现签名与我向 python 公开的方法不匹配。下面是代码

class StatusEffect
{
public:
//Virtual functions and non related ommitted
void AddCancellation(std::string &effect)
{
CancelsEffects.insert(effect);
}
}

我想在我的 python 脚本中覆盖 StatusEffect 中的一些虚拟方法,因此我创建了一个类包装器。包装器不会以任何方式覆盖或更改 AddCancellation,我只是简单地展示它以标记

struct StatusEffectWrapper : Game::StatusEffects::StatusEffect
{
//Wrappings for virtual functions here. I don't touch AddCancellation
}

我将它暴露给 python 如下:

 class_<StatusEffects::StatusEffect, boost::noncopyable, std::auto_ptr<StatusEffectWrapper> >("StatusEffect")
.def("AddCancellation", &StatusEffect::AddCancellation)
;

在我的 python 文件中,我像这样扩展基本的 StatusEffect 类:

class StatCreepEffect(StatusEffect):
def __init__(self, name, stat_, rate_, descript, uid, turns, prior, canrefresh, poseffect, cats, conds, flgs, sep, pers, cancels):
StatusEffect.__init__(self, name, descript, uid, turns, prior, canrefresh, poseffect, cats, conds, flgs, sep, pers)
self.rate = rate_
self.stat = stat_
self.PushCancellations(cancels)
def PushCancellations(self, cancels):
for cancel in cancels:
print (cancel)
self.AddCancellation(cancel)

Regen = StatCreepEffect("Regen", Stat.HP, 0.05, "Regenerates a small amount of HP every turn", PrimaryEngine.GetUID(), 14, 4, True, True, StatusCategories.SC_Regen, 0, StatusFlags.TickEffect, True, StatusPersistence.SP_Timer_Cure, ["Poison", "Poison-"])

但是,当我这样做时,出现以下错误:

Poison
Traceback (most recent call last):
File "..\..\..\Resources\Scripts\StatusEffects.py", line 27, in <module>
Regen = StatCreepEffect("Regen", Stat.HP, 0.05, "Regenerates a small amount
of HP every turn", PrimaryEngine.GetUID(), 14, 4, True, True, StatusCategories.S
C_Regen, 0, StatusFlags.TickEffect, True, StatusPersistence.SP_Timer_Cure, ["Poi
son", "Poison-"])
File "..\..\..\Resources\Scripts\StatusEffects.py", line 11, in __init__
self.PushCancellations(cancels)
File "..\..\..\Resources\Scripts\StatusEffects.py", line 23, in PushCancellati
ons
self.AddCancellation(cancel)
Boost.Python.ArgumentError: Python argument types in
StatusEffect.AddCancellation(StatCreepEffect, str)
did not match C++ signature:
AddCancellation(class Game::StatusEffects::StatusEffect {lvalue}, class std:
:basic_string<char,struct std::char_traits<char>,class std::allocator<char> > {l
value})

我不完全确定问题出在哪里。 StatCreepEffect 应该是 StatusEffect 的一个实例,不是吗? Boost::python 会自动处理字符串的转换,不是吗?我是否错误地调用了该方法?感觉像是我错过了一些小东西,但我不确定它是什么。任何帮助将不胜感激。

最佳答案

原来我需要有

void AddCancellation(std::string &effect)
{
CancelsEffects.insert(effect);
}

作为

void AddCancellation(const std::string &effect)
{
CancelsEffects.insert(effect);
}

关于c++ - Boost Python签名不匹配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6258485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com