如果,否则产生错误C2181:如果没有if,则为非法

eva*_*nal -1 c++ virtual boolean compiler-errors

我有一个具有以下定义的函数:

virtual bool Process(wtdaFileHandler &daHandler, wtdaGather &daGather);

这个函数中的所有代码路径都返回一个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;
}
Run Code Online (Sandbox Code Playgroud)

有谁能解释一下?也许这是我不知道的C++的一些警告?对我来说完全是无稽之谈.这个错误无疑是指其他的.我已经建立起来确保它不仅仅是智能感知.这是一个Win32 C++项目.

jua*_*nza 9

你需要失去这个分号:

if (process.Process(daLFDFileHandler, daGather));
                                                ^
Run Code Online (Sandbox Code Playgroud)

分号if从以下块中分离条件,然后将其解释为范围,后跟孤立else.