是否可以看到c ++中返回的值?

use*_*244 1 c++ return list

那么......我正在使用断言测试函数:( pBola1的值为1)

assert(BomboTest.TreureBola(1)==pBola1);
Run Code Online (Sandbox Code Playgroud)

BomboTest.TreureBola它是一个返回列表的随机数(在这种情况下必须返回1)的函数.

cBola* cBombo::TreureBola(int num)
{
    int posicio_aleatoria;

    posicio_aleatoria= rand() % (num);

    return(Boles.TreureElement(posicio_aleatoria)); 
}
Run Code Online (Sandbox Code Playgroud)

和TreureElement它是一个函数,它返回一个动态列表的元素,知道你想要提取的元素的位置(在这种情况下返回'retorn',它是1)

cBola* cLlista::TreureElement(int posicio)
{
    int i;
    cBola* recorreLlista;
    cBola *retorn;
    recorreLlista=primer;
    retorn = primer;
    i=0;

    if (posicio == 0)
    {
        primer = (*primer).getSeguent();
    }
    else
    {
        // Busquem la posició //
        while(i < posicio)
        {
            recorreLlista= retorn;
            retorn = (*retorn).getSeguent();
            i++;
        }
        (*recorreLlista).setSeguent( (*retorn).getSeguent() );
    }
    numElements--;
    return retorn;
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么但断言失败了.我可以看到TreureElement返回的值因为我有指针'retorn'但是我不知道TreureBola返回的值.有什么方法可以看到TreureBola在调试器中返回的值?

PD:我正在使用visual studio 2010

Luc*_*ore 6

只需创建一个本地

cBola* pTemp = BomboTest.TreureBola(1);
assert(pTemp==pBola1);
Run Code Online (Sandbox Code Playgroud)

您可以查看dissasembly并检查返回注册表,但这似乎有点矫枉过正.以上是正确的方法,其他人会在将来遇到同样的问题时感谢你.


Mar*_*sen 5

您可以随时暂时更改

assert(BomboTest.TreureBola(1)==pBola1);
Run Code Online (Sandbox Code Playgroud)

to`

auto tmp=BomboTest.TreureBola(1);
assert(tmp==pBola1);
Run Code Online (Sandbox Code Playgroud)

并在第一行放置一个断点.