是main()
函数odr-used ?例如在这样的简单程序中:
int main()
{
}
最佳答案
不,不是。不在您的简单程序中。
[basic.def.odr]
3 A function whose name appears as a potentially-evaluated expression is odr-used if it is the unique lookup result or the selected member of a set of overloaded functions ([basic.lookup], [over.match], [over.over]), unless it is a pure virtual function and either its name is not explicitly qualified or the expression forms a pointer to member ([expr.unary.op]).
main
没有出现在可能被求值的表达式中,因此它没有被 odr 使用。此外,我们必须考虑以下几点:
[basic.start.main]
3 The function main shall not be used within a program.
这是否适用于简单地调用 main 或任何用途,可能值得商榷,但它肯定会限制您在任何程序中使用 odr-use main
的选项。
在分析 odr-use 时,值得牢记的是 程序 odr-uses 实体(或不使用它们)。外部力量(例如使用 main
作为入口点的实现)不受该辩论的影响。
关于c++ - main() 函数是否使用了 odr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54166888/