【问题标题】:Error 1 error C2664: 'arl::contFolder *arl::list::setDown(arl::contFolder *,int *)' : cannot convert argument 2 from 'unsigned int' to 'int *'错误 1 ​​错误 C2664: 'arl::contFolder *arl::list::setDown(arl::contFolder *,int *)' : 无法将参数 2 从 'unsigned int' 转换为 'int *'
【发布时间】:2014-03-05 17:34:02
【问题描述】:

我有这个功能

void file::pg_down(fldr *f)
    {
        drawItem(*f, drw::Colours::blueVivid);
        f->item_pos = myList.setDown(f->active->next, f->cord.x);
        if (!strcmp(f->item_pos->name, myStr))
            f->item_pos = f->item_pos->prev;

        drawItem(*f, drw::Colours::greenVivid);
    }

调用函数

contFolder* list::setDown(contFolder* current, int *xCord)
    {
        arl::contFolder* tmp = NULL;
        arl::contFolder* i = NULL;
        for (i = current; i->next; i = i->next, xCord++)
        {
            if (!strcmp(i->name, myStr))
            {
                tmp = i;
                return tmp;
            }
        }
        tmp = i;
        return tmp;
    }

我需要函数 contFolder* list::setDown(contFolder* current, int *xCord) 来改变 xCord 的值,但不明白怎么做正确传递此参数。 因此我有错误

错误 1 ​​错误 C2664: 'arl::contFolder *arl::list::setDown(arl::contFolder *,int *)' : 无法将参数 2 从 'unsigned int' 转换为 'int *'

你会推荐什么?

【问题讨论】:

    标签: c++ c visual-studio-2012 parameter-passing


    【解决方案1】:
    myList.setDown(f->active->next, f->cord.x);
    

    应该是

    myList.setDown(f->active->next, (int*)&f->cord.x);
    

    您的函数setDown 采用int*,而不是int,因此请传递变量的地址。

    另外,您的类型不匹配。当您将坐标存储为unsigned ints 时,为什么您的函数采用int*?只要选择正确的类型...

    contFolder* list::setDown(contFolder* current, unsigned int *xCord);
    

    顺便说一句,你从来没有真正使用过xCord。你增加它,但它是一个指针的副本,所以它对f->cord.x 没有影响。你到底想在这里做什么?如果您尝试增加f->cord.x,则需要使用(*xCord)++

    【讨论】:

    • 我也试过了,虽然它显示相同的错误/
    • @Eugene:哦,不,这不是同一个错误。我刚刚意识到f->coord.x 是一个 unsigned int,而不是 int。你有一个类型不匹配。你必须投射。
    • 那么你建议做什么?
    • @Eugene:你使用演员表或改变你的类型。当您将坐标存储为unsigned ints 时,为什么您的函数采用int*
    • 错误 1 ​​错误 C2664: 'arl::contFolder *arl::list::setDown(arl::contFolder *,int *)' : 无法将参数 2 从 'unsigned int *' 转换为 ' int *'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    相关资源
    最近更新 更多