小编bbd*_*e95的帖子

在3.3中加载python模块时,我使用什么而不是PyString_AsString

我正在尝试使用此函数在我的一个c ++程序中从python加载一个函数

char * pyFunction(void)
{
    char *my_result = 0;
    PyObject *module = 0;
    PyObject *result = 0;
    PyObject *module_dict = 0;
    PyObject *func = 0;
    PyObject *pArgs = 0;

    module = PyImport_ImportModule("testPython");
    if (module == 0)
    {
        PyErr_Print();
        printf("Couldn't find python module");
    }
    module_dict = PyModule_GetDict(module); 
    func = PyDict_GetItemString(module_dict, "helloWorld"); 

    result = PyEval_CallObject(func, NULL); 
    //my_result = PyString_AsString(result); 
    my_result = strdup(my_result);
    return my_result;
}
Run Code Online (Sandbox Code Playgroud)

我应该使用什么而不是PyString_AsString?

c++ python python-module

11
推荐指数
1
解决办法
1万
查看次数

无法将“this”指针从“const Bullet”转换为“Bullet &”

我正在尝试使用我的项目符号列表。每当我运行更新项目符号代码时,它都会出现以下错误:

错误 1 ​​错误 C2662:“Bullet::detectCollision”:无法将“this”指针从“const Bullet”转换为“Bullet &”

我的列表:

std::list<Bullet> bullet_list;
Run Code Online (Sandbox Code Playgroud)

我的更新代码:

std::list<Bullet>::const_iterator cIter;
    for ( cIter = bullet_list.begin( ); cIter != bullet_list.end( ); cIter++ )
    {
        if((*cIter).detectCollision(monster.position,monster.getHeight(),monster.getWidth()))
        {
//Do stuff here
        }
        if ((*cIter).detectCollision(boss.getPosition(),boss.getHeight(),boss.getWidth()))
        {
//Do stuff here
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的检测碰撞代码:

bool Bullet::detectCollision(Vector objTwo,int heightT,int widthT)
{
if(position.getVectorX() >= objTwo.getVectorX() - (widthT/2) && position.getVectorX() <= objTwo.getVectorX() + (widthT/2)
    && position.getVectorY() >= objTwo.getVectorY() - (widthT/2)&& position.getVectorY() <= objTwo.getVectorY() + (heightT/2) && alive)
{
    return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)

c++ iterator list const-iterator

2
推荐指数
1
解决办法
1312
查看次数

标签 统计

c++ ×2

const-iterator ×1

iterator ×1

list ×1

python ×1

python-module ×1