我有以下一段代码-

void CommandProcessor::ReplacePortTag((void *) portID)
{
    std::string temp = std::string.empty();
    int start = 0;
    for (int i=0; i<CommandProcessor::fileContents.length(); i++)
    {
        if (CommandProcessor::fileContents.substr(i,6) == "<port>")
        {
            temp += CommandProcessor::fileContents.substr(start,i-start);
            temp += portID;
            start = i+6;
        }
    }
    temp += CommandProcessor::fileContents.substr(start+6,CommandProcessor::fileContents.length()-start-6);
    CommandProcessor::fileContents = temp;
}

当我尝试编译时出现错误-
error C2448: 'CommandProcessor::ReplacePortTag' : function-style initializer appears to be a function definition

我无法弄清楚哪里出了问题。我该如何修改以解决此错误?

最佳答案

这种语法意味着您是C风格的,将变量portID强制转换为void*

void CommandProcessor::ReplacePortTag((void *) portID)

如果参数应为void*,则函数声明应为
void CommandProcessor::ReplacePortTag(void* portID)

08-27 02:25