Si j'ai quelque chose comme la classe suivanteopérateur = dans Boost :: Python
class Foo
{
private:
int _bar;
public:
Foo& operator=(const Foo& other)
{
_bar = other._bar;
return *this;
}
}
est-il un moyen facile d'exporter cette fonctionnalité à python en utilisant boost :: python? La documentation ne répertorie pas et agréable et facile
.def(self = self)
Je ne suis pas un expert en python, donc je ne sais même pas si cela est nécessaire pour être honnête. Mais je veux cette fonctionnalité dans mes scripts python, donc je poste la question juste pour m'assurer.
Edit:
ici sont les erreurs du compilateur quand je fais faire def (auto = auto)
.\src\Python.cpp(12) : error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,Fn,const A1 &,const A2 &,const A3 &)' : expects 5 arguments - 1 provided
with
[
W=Foo
]
depends\common\include\boost/python/class.hpp(265) : see declaration of 'boost::python::class_<W>::def'
with
[
W=Foo
]
.\src\Python.cpp(12) : error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,Fn,const A1 &,const A2 &)' : expects 4 arguments - 1 provided
with
[
W=Foo
]
depends\common\include\boost/python/class.hpp(249) : see declaration of 'boost::python::class_<W>::def'
with
[
W=Foo
]
.\src\Python.cpp(12) : error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,A1,const A2 &)' : expects 3 arguments - 1 provided
with
[
W=Foo
]
depends\common\include\boost/python/class.hpp(242) : see declaration of 'boost::python::class_<W>::def'
with
[
W=Foo
]
.\src\Python.cpp(12) : error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,F)' : expects 2 arguments - 1 provided
with
[
W=Foo
]
depends\common\include\boost/python/class.hpp(233) : see declaration of 'boost::python::class_<W>::def'
with
[
W=Foo
]
.\src\Python.cpp(12) : error C2784: 'boost::python::class_<W> &boost::python::class_<W>::def(const boost::python::def_visitor<Derived> &)' : could not deduce template argument for 'const boost::python::def_visitor<Derived> &' from 'boost::python::self_ns::self_t'
with
[
W=Foo
]
depends\common\include\boost/python/class.hpp(223) : see declaration of 'boost::python::class_<W>::def'
with
[
W=Foo
]
bonne Ok, c'est exactement ce que je devais savoir. Je ne suis pas un expert en python, donc je ne savais pas comment ça fonctionnait. J'ai effectivement un constructeur de copie et une méthode de copie. operator = et le constructeur de copie appelle copy(), donc je suppose que je dois juste exporter le constructeur de la copie et l'appeler bien, merci! – Charles