C++ if,else产生错误C2181:非法的else,没有if

C++ if,else产生错误C2181:非法的else,没有if,c++,compiler-errors,boolean,virtual,C++,Compiler Errors,Boolean,Virtual,我有一个定义如下的函数: 虚拟bool进程wtdafilehandler&daHandler、wtdaGather&daGather this函数中的所有代码路径都返回bool,我当然调用这个函数,而不是子类中的函数。以下代码在过帐标题中产生错误: wtdaLFDProcess process; // call some methods to do initialize process and args. if (process.Process(daLFDFileHandler, daGat

我有一个定义如下的函数:

虚拟bool进程wtdafilehandler&daHandler、wtdaGather&daGather

this函数中的所有代码路径都返回bool,我当然调用这个函数,而不是子类中的函数。以下代码在过帐标题中产生错误:

wtdaLFDProcess process;

// call some methods to do initialize process and args.

if (process.Process(daLFDFileHandler, daGather));
{
     retval = 0;
}
else
{
    retval = LFD_FILE_LOCK_ERROR;
    cout << "Could not obtain file lock for processing." << endl;
    WTDA_STATUS(3,  "Error...Stopping" );
    return;
}

有人能解释一下吗?也许是我不知道的C++的一些警告?这对我来说毫无意义。这个错误无疑是指其他错误。我已经建立了确保它不仅仅是智能感知。这是一个Win32 C++项目。 您需要删除此分号:

if (process.Process(daLFDFileHandler, daGather));
                                                ^

分号从下面的块中分离if条件,然后将其解释为作用域,后面是孤立的else。

if process.processdalfdffilehandler,daGather;
删除该文件;如果行中只有

就结束了:if process.processdalfdffilehandler,daGather


您需要删除它以获得所需的输出

哦,哇,很明显。。。我在这个函数调用中遇到了其他问题,所以当我遇到错误时,我没有真正思考返回值的赋值失败了。谢谢你,我会尽我所能接受的。@I尽管你必须等一段时间,我想十分钟。@evanmcdonnal啊!很高兴知道@大多数编译器对此都有警告。如果您没有收到警告或没有看到警告,您应该提高警告级别和/或将警告视为错误,这样它们就不能被忽略。@bames53我知道,我刚刚犯了一个noob错误,因为我有其他问题,所以我认为情况更糟。例如,现在编译,函数返回false,它进入else块,我逐行遍历它,代码实际上没有执行!也许这是构建的问题,我正在远程调试,也许代码被禁用了?