0

I have a method in python that's implemented like this :

class MyClass:
    def __init__(self, i, j, k):
        self._i = i
        self._j = j
        self._k = k
    def generate_queue(self, max, min):
        # do stuff
        return queue_with_ints
class Class2:
    def __init__(self, mc):
        # mc is a MyClass object
        self._mc = mc

the C++ code (I've used list because I didn't find any documentation about a boost::python::queue, and I can always make the python function return a list instead as that wouldn't really make a difference):

class Foo : public Node{
    // constructor
    // other functions
    void do_stuff_with_queue( int max, int min){
        // o is an instance of Class2
        boost::python::object mc = (this->o).attr("_mc");
        boost::python::list q = mc.attr("generate_queue")(max, min);
        int length = extract<int>(q.attr("__len__")());
        for (int i = 0; i < length; i++){
            int subframe = boost::python::extract<int>(q[i]);
            // do stuff
        }
}

error output:

erreur: conversion from ‘boost::python::detail::dependent<boost::python::api::object, int>::type {aka boost::python::api::object}’ to non-scalar type ‘boost::python::list’ requested

I'm not sure what is happening here, the only other "non scalar type" error I've seen is when someone tried to assign a pointer to an object from this post. How can I fix this?

Thanks

qwerty_99
  • 640
  • 5
  • 20
  • There's no `boost::python::queue`, since Queue isn't a built-in, but a regular Python class. Just store it in `boost::python::object`, and use `attr`, just like you do with `MyClass` instance. – Dan Mašek Jul 09 '20 at 18:52
  • I ended up using a list instead, would this work? It compiles but it's yet to be tested (I'll convert the python queue to list before passing it to C++) `boost::python::list q = boost::python::extract(mc.attr("generate_queue")(max, min));` Edit : format – qwerty_99 Jul 09 '20 at 19:07

0 Answers0