我目前在开放源代码平台上研究与c ++集成的一段python代码。 Python类和定义将参数传递给c ++文件,然后函数运行。我的c ++文件是一个packet_sink文件,它带有3个输入参数,如下所述:

packet_sink (const std::vector<unsigned char>& sync_vector,
                                msg_queue_sptr target_queue, int threshold)


python代码的部分如下:

   self.threshold = -1
   if access_code is None:
       code = tuple(string_to_1_0_list(default_access_code))
       access_code = to_1_0_string(code)
   if not packet_utils.is_1_0_string(access_code):
       raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
   print " _access_code : %s " %(self._access_code,)

   self._msgq = gr.msg_queue()# holds packets fromthe PHY

   self.phy_anay_demod= phy_anay_demod(self,*args, **kwargs)
   self._packet_sink =gr.packet_sink(self._access_code,self._msgq,self.threshold)


_access_code的值为:

0011010110111011001001010100011101001111001100010000010000111111


但是我收到的错误消息如下:


  TypeError:在方法“ packet_sink”中,类型为“ std :: vector > const&”的参数1。


如果不是解决问题的方法,有人可以帮助我理解该错误。

最佳答案

在我看来就像self._access_code应该是一个0或1的整数列表或元组。

Gnuradio使用SWIG从C ++代码创建python接口。 SWIG将C ++向量映射到python列表。因此,如果传入整数列表(0或1),则应将其愉快地转换为向量。

我的猜测是您的self._access_code是一个字符串,您需要对其应用string_to_1_0_list函数。

关于c++ - C++和python: vector 参数的TypeError解析?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9406763/

10-11 23:12
查看更多