C++ 返回 boolean 值 95

标签 c++ return boolean

在 C++ 中返回 boolean 值的问题..

bool find( const TrieNode &node, const string word )
{

    if (word.length() == 0)
    {
         if (node.isWord)
         {
         cout << "TRUE" << endl;
         return true;
         }

         else
         {
         cout << "FALSE" << endl;
         return false;
         }
    }

    char firstletter = word.at(0);
    int index = firstletter - 'a';

    if (node.letters[index] == NULL)
    {
    return false;
    }

    else
    {
    find (*node.letters[index],word.substr(1,(word.length() - 1)));
    }

}

我主要有

cout << find(*mynode,"word") << endl;

将屈服于:

错误

95

显然,FALSE 的 cout 意味着该函数返回 false。但是,当我打印出该函数的结果时,我得到 95,其计算结果为 true。它为什么会这样做?

谢谢

最佳答案

您缺少最后的返回语句,所以您得到的是 EAX 低字节中的任何内容,这是随机垃圾。您可能希望在函数的最后 return true;

您应该提高编译器的警告级别,因为它应该告诉您这一点(类似于“并非所有控制路径都返回一个值”)。

关于C++ 返回 boolean 值 95,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6381799/

相关文章:

c++ - 如何检测 boost::function 是否是纯虚拟的?

c++ - 在getline之后在c++中输入

ios - 多重过滤 Swift 的 boolean 语句

r - 为什么 TRUE == "TRUE"在 R 中是 TRUE?

C++ 和 Cuda 在 Visual Studio 2013 中的速度

c++ - Qt - 重新实现 QIODevice 以实时听到我自己的声音

java - 尝试 catch block 变量超出范围

c - 如何管理从 C 函数返回的内存

java - 触发 Action 后从 JFrame 返回

c++ - 有没有办法用 bool 做类似 "post switch"的操作?